Search code examples
pythongcloudgoogle-cloud-sdk

Mac gcloud install ImportError: No module named __future__


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

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).

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
>>> 

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.

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?


Solution

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

    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.

    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.