我正在尝试使用google translate api,并且应用引擎标准环境正在调用api。在我的开发环境dev_appserver.py中,抛出以下错误ImportError: No module named pkg_resources
我检查了文件夹,没有名为“pkg_resources”的文件。有人面临类似的问题吗?
from google.cloud import translate
translate_client = translate.Client()
Traceback (most recent call last):
File "C:\Users\mdkamalhossain\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\runtime\wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "C:\Users\mdkamalhossain\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\api\lib_config.py", line 351, in __getattr__self._update_configs()
File "C:\Users\mdkamalhossain\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\api\lib_config.py", line 287, in _update_configs
self._registry.initialize()
File "C:\Users\mdkamalhossain\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\api\lib_config.py", line 160, in initialize
import_func(self._modname)
File "C:\my_repo_work\gae-NpsFeedback\appengine_config.py", line 9, in <module>`enter code here`
from google.cloud import translate
File "C:\Python27\lib\site-packages\google\cloud\translate.py", line 18, in <module>
from google.cloud.translate_v2 import __version__
File "C:\Python27\lib\site-packages\google\cloud\translate_v2\__init__.py", line 18, in <module>
from pkg_resources import get_distribution
ImportError: No module named pkg_resources
答案 0 :(得分:0)
回溯表明translate
软件包已安装在本地系统上,而不是应用程序内部:
File "C:\Python27\lib\site-packages\google\cloud\translate.py"
对于标准环境GAE,您需要在应用程序中安装库。来自Copying a third-party library:
使用不在内置列表中的第三方库 与运行时捆绑在一起的库:
创建一个目录来存储第三方库,例如lib /.
mkdir lib
- 醇>
使用带有-t标志的pip(版本6或更高版本)将库复制到您在上一步中创建的文件夹中。对于 例如:
pip install -t lib/ <library_name>