本文介绍了Mac gcloud install ImportError:没有名为__future__的模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为Mac安装gcloud时,根据docs install.sh命令时出现此错误noreferrer>此处:

When installing gcloud for mac I get this error when I run the install.sh command according to docs here:

Traceback (most recent call last):
  File "/path_to_unzipped_file/google-cloud-sdk/bin/bootstrapping/install.py", line 8, in <module>
    from __future__ import absolute_import

我检查了一下,并在安装shell脚本中回显了一些东西.它正在正确设置环境变量(指向我的默认python安装,指向gcloud SDK的正确位置).

I poked through and echoed out some stuff in the install shell script. It is setting the environment variables correctly (pointing to my default python installation, pointing to the correct location of the gcloud SDK).

如果我只是输入p​​ython解释器(使用安装脚本在运行install.py时指向的默认python),则可以导入模块:

If I just enter the python interpreter (using the same default python that the install script points to when running install.py) I can import the module just fine:

>>> from __future__ import absolute_import
>>>

只有其他值得注意的信息是我的默认python设置是我通过brew安装的python 2.7.15创建的虚拟环境.虚拟环境python bin首先位于我的PATH中,因此pythonpython2python2.7都调用正确的二进制文件.到目前为止,我在此设置上安装软件包没有其他问题.

Only other information worth noting is my default python setup is a virtual environment that I create from python 2.7.15 installed through brew. The virtual environment python bin is first in my PATH so python and python2 and python2.7 all invoke the correct binary. I've had no other issues installing packages on this setup so far.

如果我回显了install.sh脚本的最后一行(调用install.py脚本),则会显示/path_to_virtualenv/bin/python -S /path_to_unzipped_file/google-cloud-sdk/bin/bootstrapping/install.py,这是正确的python.还是我错过了什么?

If I echo the final line of the install.sh script that calls the install.py script it shows /path_to_virtualenv/bin/python -S /path_to_unzipped_file/google-cloud-sdk/bin/bootstrapping/install.py which is the correct python. Or am I missing something?

推荐答案

该脚本使用 -S命令行开关,它会禁用加载 site模块在启动时.

The script uses the -S command-line switch, which disables loading the site module on start-up.

但是,它是安装在virtualenv中的自定义专用site模块,可以使virtualenv正常工作.因此,-S开关和virtualenvs不兼容,其中-S设置的基本导入内容(例如from __future__完全崩溃).

However, it is a custom dedicated site module installed in a virtualenv that makes a virtualenv work. As such, the -S switch and virtualenvs are incompatible, with -S set fundamental imports such as from __future__ break down entirely.

您可以从install.bat命令中删除-S开关,也可以在您调用真正的virtualenv Python时使用包装程序脚本从命令行中删除它.

You can either remove the -S switch from the install.bat command or use a wrapper script to strip it from the command line as you call your real virtualenv Python.

这篇关于Mac gcloud install ImportError:没有名为__future__的模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 06:35