【问题标题】:I am trying to use google translate api and the api is being called by app engine standard environment我正在尝试使用google translate api,并且该api被应用引擎标准环境调用
【发布时间】:2018-10-10 08:03:43
【问题描述】:

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

【问题讨论】:

  • 我认为this link 会帮助你:)
  • 你能显示你的 appengine_config.py 吗?

标签: python-2.7 google-app-engine google-api-python-client google-translation-api


【解决方案1】:

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

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

对于标准环境 GAE,您需要在应用程序中安装该库。来自Copying a third-party library

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

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

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

    pip install -t lib/ <library_name>
    

【讨论】:

    猜你喜欢
    • 2018-06-03
    • 2018-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-01-25
    • 2018-11-15
    • 2019-05-12
    • 2021-04-15
    相关资源
    最近更新 更多