Programing

ImportError : 이름이 apiclient.discovery 인 모듈이 없습니다.

crosscheck 2020. 6. 27. 11:12
반응형

ImportError : 이름이 apiclient.discovery 인 모듈이 없습니다.


Google App Engine의 Python에서 Google Translate API를 사용했지만 이 오류가 발생 했지만 해결 방법을 모르겠습니다.

<module>
from apiclient.discovery import build
ImportError: No module named apiclient.discovery

Google App Engine SDK를 나타내는 환경설정 하고 Google Apps Engine에 다시 업로드하면 항상 오류가 발생합니다 .

오류 : 서버 오류

서버에 오류가 발생하여 요청을 완료 할 수 없습니다. 문제가 지속되면 문제를보고하고이 오류 메시지와 원인이 된 쿼리를 언급하십시오.

고치는 방법을 알려주세요.

감사

업데이트 : 수정 Nijjin의 도움에 따라 다음 폴더를 추가하여 문제를 해결했습니다.

apiclient, gflags, httplib2, oauth2client, uritemplate


이 간단한 설치로 이러한 종속성을 얻을 수 있어야합니다.

sudo pip install --upgrade google-api-python-client

이것은 python 빠른 시작 페이지에 설명되어 있습니다.


apiclient도서관의 원래 이름이었습니다.
어느 시점에서로 전환되었습니다 googleapiclient.

코드가 Google App Engine에서 실행중인 경우 둘 다 작동합니다.

google-api-python-client가 설치된 상태에서 애플리케이션을 직접 실행하는 경우 둘 다 작동합니다.

패키지 모듈 의 소스 코드를apiclient__init__.py 살펴보면 apiclient모듈이 이전 버전과의 호환성을 위해 단순히 유지되어 있음을 알 수 있습니다 .

apiclient를 googleapiclient의 별칭으로 유지하십시오.

따라서 별칭을 레거시 코드를 위반하지 않도록 유지 관리 googleapiclient했기 때문에 코드에서 실제로 사용해야합니다 apiclient.

# bad
from apiclient.discovery import build

# good
from googleapiclient.discovery import build

apiclientappengine 런타임에서 제공하는 타사 라이브러리 목록에 없습니다 ( http://developers.google.com/appengine/docs/python/tools/libraries27) .

당신은 복사 할 필요가 apiclient프로젝트 디렉토리 및 이러한 복사해야 uritemplate&을 httplib2너무.

참고 : 문서 목록에없는 타사 라이브러리는 appengine 프로젝트 디렉토리에 복사해야합니다.


앱 엔진 프로젝트의 경우 다음을 입력하여 로컬로 lib를 설치해야합니다.

pip install -t lib google-api-python-client

여기서 더 읽어 보세요


위의 해결책 중 어느 것도 효과가 없다면 Anaconda를 통해 파이썬을 설치했는지 고려하십시오. 이 경우 conda와 함께 Google API 라이브러리를 설치하면 문제가 해결 될 수 있습니다.

운영:

python --version

당신이 같은 것을 얻는다면

Python 3.6.4 :: Anaconda, Inc.

그런 다음 시도하십시오.

conda install google-api-python-client

bgoodr이 의견에서 지적했듯이 Google API 라이브러리를 얻으려면 채널 (생각 저장소)을 지정해야 할 수도 있습니다. 작성 당시 이것은 명령을 실행하는 것을 의미합니다.

conda install -c conda-forge google-api-python-client

https://anaconda.org/conda-forge/google-api-python-client 에서 자세히 알아보십시오.


프로젝트의 다운로드 섹션에 google-api-python-client-gae- <version> .zip 과 같은 이름의 라이브러리 및 모든 종속 항목이 포함 된 Google API Python 클라이언트 라이브러리 용 다운로드가 있습니다 . 이것을 App Engine 프로젝트에 압축 해제하십시오.


google-api-python-client설치되어 있는지 확인하십시오 . apiclient설치 한 경우 충돌이 발생합니다. 따라서 다음을 실행하십시오.

sudo pip uninstall apiclient

URITemplate 모듈 설치 버그로 인해 동일한 문제가 발생했습니다.

이것은 문제를 해결했다 :

pip install --force-reinstall uritemplate.py

I fixed the problem by reinstalling the package with:

pip install --force-reinstall google-api-python-client

I got this same error when working on a project to parse recent calendar events from Google Calendar.

Using the standard install with pip did not work for me, here is what I did to get the packages I needed.

Go directly to the source, here is a link for the google-api-python-client, but if you need a different language it should not be too different.

https://github.com/google/google-api-python-client

Click on the green "Clone or Download" button near the top left and save it as a zip file. Move the zip to your project folder and extract it there. Then cut all the files from the folder it creates back into the root of your project folder.

Yes, this does clutter your work space, but many compilers have ways to hide files.

After doing this the standard

from googleapiclient import discovery

works great.

Hope this helps.


for python3 this worked for me:

sudo pip3 install --upgrade google-api-python-client

"google-api-python-client" requires:

pip install uritemplate.py

to fix problem on GAE Development Server:

from googleapiclient.discovery import build

ImportError: No module named googleapiclient.discovery

I encountered the same issue. This worked:

>>> import pkg_resources
>>> pkg_resources.require("google-api-python-client")
[google-api-python-client 1.5.3 (c:\python27), uritemplate 0.6 (c:\python27\lib\site-packages\uritemplate-0.6-py2.7.egg), six 1.10.0 (c:\python27\lib\site-packages\six-1.10.0-py2.7.egg), oauth2client 3.0.0 (c:\python27\lib\site-packages\oauth2client-3.0.0-py2.7.egg), httplib2 0.9.2 (c:\python27\lib\site-packages\httplib2-0.9.2-py2.7.egg), simplejson 3.8.2 (c:\python27\lib\site-packages\simplejson-3.8.2-py2.7-win32.egg), six 1.10.0 (c:\python27\lib\site-packages\six-1.10.0-py2.7.egg), rsa 3.4.2 (c:\python27\lib\site-packages\rsa-3.4.2-py2.7.egg), pyasn1-modules 0.0.8 (c:\python27\lib\site-packages\pyasn1_modules-0.0.8-py2.7.egg), pyasn1 0.1.9 (c:\python27\lib\site-packages\pyasn1-0.1.9-py2.7.egg)]

>>> from apiclient.discovery import build
>>> 

It only worked with me when I used sudo:

sudo pip install --upgrade google-api-python-client

참고URL : https://stackoverflow.com/questions/18267749/importerror-no-module-named-apiclient-discovery

반응형