编辑:
问题是我正在尝试从ouath2client
pip 库导入但我有一个名为的当前模块,该模块Whatever
使用了本地版本ouath2client
- 如果我尝试更新Whatever
失败。
所以我想ouath2client
从site-packages
forpubsub
但本地目录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
>>>
然后它起作用了,很奇怪。