我在 MacOS 上。我的默认 Python 是从 Python 2.7.15 的 brew 安装创建的虚拟环境。我的PATH设置为 venv 是默认的python。python2.7我在安装 gcloud 时遇到了一些问题,这些问题已解决,并且我已成功安装 gcloud。
PATH
python
python2.7
但是,任何时候我尝试运行任何gcloud命令时,我仍然会得到安装时看到的相同的 ImportError。
gcloud
Traceback (most recent call last): File "/path_to_gcloudsdk/google-cloud-sdk/lib/gcloud.py", line 20, in <module> from __future__ import absolute_import ImportError: No module named __future__
每条评论请求的附加信息:
当我进入我的默认 python 解释器并运行时输出import sys; print(sys.path):
import sys; print(sys.path)
[ '' '/path_to_virtual_env/lib/python27.zip' '/path_to_virtual_env/lib/python2.7' '/path_to_virtual_env/lib/python2.7/plat-darwin' '/path_to_virtual_env/lib/python2.7/plat-mac' '/path_to_virtual_env/lib/python2.7/plat-mac/lib-scriptpackages' '/path_to_virtual_env/lib/python2.7/lib-tk' '/path_to_virtual_env/lib/python2.7/lib-old' '/path_to_virtual_env/lib/python2.7/lib-dynload' '/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7' '/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin' '/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk' '/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac' '/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages' '/path_to_virtual_env/lib/python2.7/site-packages' ]
最终出现了与安装时遇到的问题相同的问题。shellgoogle-cloud-sdk/bin/gcloud脚本使用标志-S来运行gcloud.py。
我编辑了 shell 脚本,以便它不添加任何 python 参数,现在一切运行正常。