【问题标题】:Importing and using the google-cloud-storage module in appengine standard environment在 appengine 标准环境中导入和使用 google-cloud-storage 模块
【发布时间】:2017-04-20 09:49:43
【问题描述】:

我已将google-cloud-storage 安装到我的appengine 项目中的lib 文件夹中。然后,在我的appengine_config.py 文件中,我有:

import sys import os.path sys.path.insert(0, os.path.join(os.path.dirname(__file__), 'lib'))

appengine_config.pylib(一个目录)是同一个父目录中的子目录。

这样,我希望 appengine 会加载库。但是,当我在我的 main.py 文件中进行导入时,例如 from google.cloud import storage,我收到如下导入错误:ImportError: No module named google.cloud.storage

是否可以在 appengine 标准环境中使用类似的第三方库。如果是,如何?如果不是,请解释原因吗?

【问题讨论】:

    标签: google-cloud-storage google-app-engine-python


    【解决方案1】:

    是的,应该可以在 Appengine 标准环境中使用 google-cloud-storage。我可以按照您描述的方式使用google-cloud-translate。但是,您的 appengine_config.py 似乎不正确。试试这个:

    import os
    from google.appengine.ext import vendor
    vendor.add(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib'))
    

    假设您的lib 文件夹和appengine_config.py 文件位于同一个文件夹中。


    注意
    虽然我需要将以下内容添加到appengine_config.py 文件中,以防止出现ImportError: No module named pwd 错误。

    import os.path
    
    def patched_expanduser(path):
        return path
    
    os.path.expanduser = patched_expanduser
    

    根据this post.

    【讨论】:

      猜你喜欢
      • 2018-12-18
      • 1970-01-01
      • 1970-01-01
      • 2016-03-30
      • 2019-10-27
      • 2018-06-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-01
      相关资源
      最近更新 更多