1

我正在尝试使用 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
4

1 回答 1

0

回溯表明该translate软件包安装在您的本地系统上,而不是您的应用程序内:

File "C:\Python27\lib\site-packages\google\cloud\translate.py"

对于标准环境 GAE,您需要在应用程序中安装该库。从复制第三方库

要使用不在与运行时捆绑的内置库列表中的第三方库:

  1. 创建一个目录来存储您的第三方库,例如 lib/。

    mkdir lib
    
  2. 使用带有 -t 标志的 pip(版本 6 或更高版本)将库复制到您在上一步中创建的文件夹中。例如:

    pip install -t lib/ <library_name>
    
于 2018-04-30T16:40:54.440 回答