首页 文章

在python应用程序中导入Google Cloud Bigquery api模块时出错

提问于
浏览
3

我试图将bigquery导入我的python应用程序 from google.cloud import bigquery 并使用dev_appserver.py在本地运行它,但是我收到一个错误:

File "/Volumes/Budhi/Users/anjas/Projects/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
File "/Volumes/Budhi/Users/anjas/Projects/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
handler, path, err = LoadObject(self._handler)
File "/Volumes/Budhi/Users/anjas/Projects/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
obj = __import__(path[0])
File "/Volumes/Budhi/Users/anjas/Projects/wordworks/urlworker/main.py", line 9, in <module>
from google.cloud import bigquery
File "/Volumes/Budhi/Users/anjas/Projects/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 999, in load_module
raise ImportError('No module named %s' % fullname)
ImportError: No module named google.cloud.bigquery

我用pip安装了bigquery lib:

pip install --upgrade google-cloud-bigquery

此外,我已尝试将其作为3d方库安装到lib目录中,但没有结果 .

虽然它在我尝试从python shell导入bigquery lib时有效:

Python 2.7.10 (default, Jul 30 2016, 18:31:42) 
[GCC 4.2.1 Compatible Apple LLVM 8.0.0 (clang-800.0.34)] on darwin
Type "help", "copyright", "credits" or "license" for more  information.
>>> from google.cloud import bigquery
>>>

Update:

似乎安装到project / lib /文件夹的“google”模块与google-cloud-sdk / platform / google_appengine中的“google”模块发生冲突 .

当试图做

from google.cloud import bigquery

python在 google-cloud-sdk/platform/google_appengine/google 里找不到 project/lib/google/cloud 里面的模块

有任何想法吗?

3 回答

  • 0

    您是否在appengine_config.py中添加了lib文件夹?

    from google.appengine.ext import vendor
    vendor.add('lib')
    
  • 0

    我有同样的问题 . 如果您在本地环境中运行此命令,则可能需要尝试将lib文件夹位置添加到$ PYTHONPATH环境变量中,或者在导入bigquery lib之前添加下面的代码行,该lib将lib文件夹位置插入到字符串列表中指定模块的搜索路径 .

    import sys    
    sys.path.insert(0, 'lib')
    

    我相信这是有效的,因为现在python文件不需要在包内 .

  • 0

    我认为你正在经历一些非常接近我正在经历的事情,尽管我在测试期间看到它 .

    我想这可能是因为google sdk所需的路径操作:sdk附带的lib在你放入libs文件夹之前会被看到 .

    这是我发生的事情,有一些细节:

    Wrong dependency in Google Cloud SDK for google-auth?

相关问题