编辑:
问题在于我尝试从ouath2client
点子库导入
但
我有一个名为Whatever
的当前模块使用本地版ouath2client
- 如果我尝试更新Whatever
失败。
所以我想使用ouath2client
中的site-packages
pubsub
但是ouath2client
模块的本地目录Whatever
。
试过这样:
unique_path = '/root/.virtualenvs/simple_worker/lib/python2.7/site-packages'
unique_path = '/root/.virtualenvs/simple_worker/lib/python2.7/site-packages'
sys.path.insert(0, unique_path)
from google.cloud import pubsub
sys.path.remove(unique_path)
但我仍然得到ImportError: No module named service_account
尝试运行pub sub。收到此错误:
File "/proj/Backend/WorkerScripts/runRecognizerAlgo/run.py", line 748, in <module>
from google.cloud import pubsub
File "/root/.virtualenvs/app_engine_workers/local/lib/python2.7/site-packages/google/cloud/pubsub/__init__.py", line 27, in <module>
from google.cloud.pubsub.client import Client
File "/root/.virtualenvs/app_engine_workers/local/lib/python2.7/site-packages/google/cloud/pubsub/client.py", line 19, in <module>
from google.cloud.client import JSONClient
File "/root/.virtualenvs/app_engine_workers/local/lib/python2.7/site-packages/google/cloud/client.py", line 17, in <module>
from oauth2client.service_account import ServiceAccountCredentials
ImportError: No module named service_account
相关点数:
gapic-google-pubsub-v1==0.10.1
google-cloud-pubsub==0.21.0
grpc-google-pubsub-v1==0.10.1
oauth2client==3.0.0
在oauth2client
目录中检查,但我确实看到了service_account
ls /root/.virtualenvs/app_engine_workers/lib/python2.7/site-packages/oauth2client/
__init__.py _openssl_crypt.py _pycrypto_crypt.py clientsecrets.py crypt.pyc service_account.pyc util.pyc
__init__.pyc _openssl_crypt.pyc _pycrypto_crypt.pyc clientsecrets.pyc file.py tools.py
_helpers.py _pure_python_crypt.py client.py contrib file.pyc tools.pyc
_helpers.pyc _pure_python_crypt.pyc client.pyc crypt.py service_account.py util.py
所以我不知道/google/cloud/client.py
试图从哪里导入
尝试直接从python控制台导入时
(app_engine_workers)root@worker-test-docker-delete2:/proj/Backend/Framework/Workers# p
Python 2.7.3 (default, Mar 13 2014, 11:03:55)
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from google.cloud import pubsub
>>>
然后它有效,很奇怪。