为什么我不能在Python中导入Google Cloud客户端库?

时间:2019-01-18 02:40:36

标签: python google-cloud-platform

我正在使用Python 2.7.10。

我只是尝试运行from google.cloud import storage,但我得到了ImportError: No module named google.cloud

google-cloud似乎已正确安装。 pip install google-cloud返回Requirement already satisfied: google-cloud in /Library/Python/2.7/site-packages (0.34.0),而pip show google-cloud返回:

Name: google-cloud
Version: 0.34.0
Summary: API Client library for Google Cloud
Home-page: https://github.com/GoogleCloudPlatform/google-cloud-python
Author: Google Cloud Platform
Author-email: googleapis-publisher@google.com
License: Apache 2.0
Location: /Library/Python/2.7/site-packages
Requires: 
Required-by: 

编辑:感谢下面的Duy提醒我有关下一步的信息。 运行pip install google-cloud-storage会引发很多错误:

Using cached https://files.pythonhosted.org/packages/7b/7c/c9386b82a25115cccf1903441bba3cbadcfae7b678a20167347fa8ded34c/pyasn1-0.4.5-py2.py3-none-any.whl
protobuf 3.6.1 has requirement six>=1.9, but you'll have six 1.4.1 which is incompatible.
google-api-core 1.7.0 has requirement six>=1.10.0, but you'll have six 1.4.1 which is incompatible.
google-auth 1.6.2 has requirement six>=1.9.0, but you'll have six 1.4.1 which is incompatible.
Installing collected packages: setuptools, protobuf, googleapis-common-protos, urllib3, certifi, chardet, idna, requests, futures, pyasn1, rsa, pyasn1-modules, cachetools, google-auth, google-api-core, google-cloud-core, google-resumable-media, google-cloud-storage
  Found existing installation: setuptools 18.5
    Uninstalling setuptools-18.5:
Could not install packages due to an EnvironmentError: [('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.pyc', '/private/var/folders/_h/5cqnls4d2jxckyjk70267q_c0000gp/T/pip-uninstall-ZBmwkH/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.pyc', "[Errno 1] Operation not permitted: '/private/var/folders/_h/5cqnls4d2jxckyjk70267q_c0000gp/T/pip-uninstall-ZBmwkH/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.py', '/private/var/folders/_h/5cqnls4d2jxckyjk70267q_c0000gp/T/pip-uninstall-ZBmwkH/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.py', "[Errno 1] Operation not permitted: '/private/var/folders/_h/5cqnls4d2jxckyjk70267q_c0000gp/T/pip-uninstall-ZBmwkH/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.py', '/private/var/folders/_h/5cqnls4d2jxckyjk70267q_c0000gp/T/pip-uninstall-ZBmwkH/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.py', "[Errno 1] Operation not permitted: '/private/var/folders/_h/5cqnls4d2jxckyjk70267q_c0000gp/T/pip-uninstall-ZBmwkH/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/markers.py'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.pyc', '/private/var/folders/_h/5cqnls4d2jxckyjk70267q_c0000gp/T/pip-uninstall-ZBmwkH/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.pyc', "[Errno 1] Operation not permitted: '/private/var/folders/_h/5cqnls4d2jxckyjk70267q_c0000gp/T/pip-uninstall-ZBmwkH/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib/__init__.pyc'"), ('/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib', '/private/var/folders/_h/5cqnls4d2jxckyjk70267q_c0000gp/T/pip-uninstall-ZBmwkH/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib', "[Errno 1] Operation not permitted: '/private/var/folders/_h/5cqnls4d2jxckyjk70267q_c0000gp/T/pip-uninstall-ZBmwkH/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/_markerlib'")]

我不了解环境错误是什么,我的所有搜索都遇到了无益的兔子洞。

3 个答案:

答案 0 :(得分:0)

不推荐使用google-cloud软件包,您应该卸载并安装google-cloud-storage

答案 1 :(得分:0)

您必须使用python环境。

pip install virtualenv
virtualenv <your-env>
source <your-env>/bin/activate
<your-env>/bin/pip install google-cloud-python

在此处查看有关virtualenv https://cloud.google.com/python/setup

的更多详细信息

答案 2 :(得分:-1)

您忘记安装pip install google-cloud-storage