[英]Error importing Google Cloud Bigquery api module in python app
I am trying to import bigquery into my python app from google.cloud import bigquery
and run it locally with dev_appserver.py, but I receive an error: 我试图from google.cloud import bigquery
导入bigquery到我的python应用程序并使用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
I have installed bigquery lib with pip: 我用pip安装了bigquery lib:
pip install --upgrade google-cloud-bigquery
Also I've tried installing it as 3d party library into lib directory with no result. 此外,我已尝试将其作为3d方库安装到lib目录中,但没有结果。
Though it works when I try importing bigquery lib from python shell: 虽然它在我尝试从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: 更新:
It seems that "google" module installed to project/lib/ folder is clashing with "google" module in google-cloud-sdk/platform/google_appengine. 似乎安装到project / lib /文件夹的“google”模块与google-cloud-sdk / platform / google_appengine中的“google”模块发生冲突。
When trying to do 当试图做
from google.cloud import bigquery
python looks for the module inside google-cloud-sdk/platform/google_appengine/google not inside project/lib/google/cloud python寻找google-cloud-sdk / platform / google_appengine / google里面的模块不在project / lib / google / cloud里面
Any ideas? 有任何想法吗?
I experienced exactly the same error and fixed this by deleting google folder in appengine sdk or you can just try to copy that to your lib folder . 我遇到了完全相同的错误并通过删除appengine sdk中的google文件夹来修复此问题,或者您可以尝试将其复制到您的lib文件夹中。 This will fix the problem on local development environment but you need to revert this when deploying your service on production. 这将解决本地开发环境中的问题,但您需要在生产时部署服务时还原此问题。
I could not find a workaround to keep both google-cloud-sdk/platform/google_appengine/google and project/lib/google/cloud . 我找不到一个解决方法来保持google-cloud-sdk / platform / google_appengine / google和project / lib / google / cloud 。 You need to delete one of them 您需要删除其中一个
Did you add the lib folder in the appengine_config.py? 您是否在appengine_config.py中添加了lib文件夹?
from google.appengine.ext import vendor
vendor.add('lib')
I had the same problem. 我有同样的问题。 If you're running this on your local environment, you may want to try adding the lib folder location into your $PYTHONPATH environment variable or adding below code lines before you import the bigquery lib which inserting the lib folder location into the a list of strings that specifies the search path for modules. 如果您在本地环境中运行此命令,则可能需要尝试将lib文件夹位置添加到$ PYTHONPATH环境变量中,或者在导入bigquery lib之前添加下面的代码行,该lib将lib文件夹位置插入到字符串列表中指定模块的搜索路径。
import sys
sys.path.insert(0, 'lib')
I believe this works because now python files don't need to be inside of a package. 我相信这是有效的,因为现在python文件不需要在包内。
I think you are experiencing something very close to what i am experiencing, though i am seeing it during tests. 我认为你正在经历一些非常接近我正在经历的事情,尽管我在测试期间看到它。
I think it might be because of the path manipulation needed by google sdk: the libs shipped with the sdk are being seen before the ones you are putting in the libs folder. 我想这可能是因为google sdk所需的路径操作:sdk附带的lib 在你放入libs文件夹之前会被看到。
Here's what happens to me, with some details: 这是我发生的事情,有一些细节:
Wrong dependency in Google Cloud SDK for google-auth? Google Cloud SDK中针对google-auth的错误依赖关系?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.