5

Moving from an AWS setup to GCE for the first time, so kindly bear with my naive questions.

During the step ./google-cloud-sdk/install.sh, I encountered the following the error:

  Welcome to the Google Cloud SDK!
  Traceback (most recent call last):
    File "/Users/t/Desktop/./google-cloud-sdk/bin/bootstrapping/install.py", line 8, in <module>
      import bootstrapping
    File "/Users/t/Desktop/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 19, in <module>
      from googlecloudsdk.core.credentials import store as c_store
    File "/Users/t/Desktop/google-cloud-sdk/lib/googlecloudsdk/core/credentials/store.py", line 34, in <module>
      from googlecloudsdk.core.credentials import creds
    File "/Users/t/Desktop/google-cloud-sdk/lib/googlecloudsdk/core/credentials/creds.py", line 40, in <module>
      import sqlite3
    File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sqlite3/__init__.py", line 24, in <module>
      from dbapi2 import *
    File "/usr/local/Cellar/python/2.7.11/Frameworks/Python.framework/Versions/2.7/lib/python2.7/sqlite3/dbapi2.py", line 28, in <module>
      from _sqlite3 import *
  ImportError: No module named _sqlite3

Upon close inspection, I noticed that there were two python2.7 versions in my /usr/local/Cellar/python viz. 2.7.10_2 and 2.7.11.

Strangely enough, when I go to python command line, this issue:

  Python 2.7.10 (default, Oct  6 2017, 22:29:07)
  [GCC 4.2.1 Compatible Apple LLVM 9.0.0 (clang-900.0.31)] on darwin
  Type "help", "copyright", "credits" or "license" for more information.

  >>> import sqlite3
  >>> from _sqlite3 import *
  >>> print('hello, this seems to work')
      hello, this seems to work

While it is unfortunate that the install.sh is picking up py2.7.11 version and not the python version from the System, I am not sure if we can set some environmental variables, (e.g. $CLOUDSDK_PYTHON before we start with installation).

komarkovich
  • 2,223
  • 10
  • 20
envy_intelligence
  • 453
  • 1
  • 6
  • 21

6 Answers6

5

Yes, you should set your $CLOUDSDK_PYTHON environment variable to point to the correct Python installation. See a similar question: google-cloud-sdk installation not finding right Python 2.7 version in CentOS /usr/local/bin

  • 2
    If anyone is running into this issue with asdf version manager, I was able to fix this by setting $CLOUDSDK_PYTHON to my system python at /usr/bin/python3.8 – Ivan -Oats- Storck Dec 19 '20 at 19:16
3

I am using pyenv and install different python versions, and I have to configure CLOUDSDK_PYTHON to point to the system python under /usr/local/bin to make it work.

Pointing to somewhere inside pyenv e.g /home/user/.pyenv/shims/python or /home/user/.pyenv/versions/2.7.15/bin/python2 will not solve this.

Chuan
  • 3,103
  • 1
  • 19
  • 23
2

Hit this issue today and, since python2 has reached its end-of-life it's better to start using python3.

Here's a set of commands that's worked for me on CentOS 7:

Some important points:

  • Install sqlite-devel package (the name may change depending on your distro)
  • Pass --enable-loadable-sqlite-extensions when configuring your Python interpreter
  • Use altinstall so that you don't ruin yum on your host as it relies on python2 being the default interpreter
sudo yum install gcc openssl-devel bzip2-devel libffi-devel sqlite-devel
cd /usr/src
sudo wget https://www.python.org/ftp/python/3.8.6/Python-3.8.6.tgz
sudo tar xzf Python-3.8.6.tgz
cd Python-3.8.6
sudo ./configure --enable-optimizations --enable-loadable-sqlite-extensions
sudo make altinstall
sudo rm /usr/src/Python-3.8.6.tgz
sudo ln -s /usr/local/bin/python3.8 /usr/bin/python3
sudo ln -s /usr/local/bin/python3.8 /usr/local/bin/python3
Jean Spector
  • 916
  • 9
  • 9
0

This is The issue when while running installation link cloudsql is not able to find the executable python So to solve it I adopted this method

  1. which python It will give the path of python something like usr/bin/python

  2. make the symlink for the execution

    ls -s usr/bin/python usr/local/bin/python

shaharyar
  • 59
  • 6
0

You need to set the environment like if you are using oh-my-zsh -

export CLOUDSDK_PYTHON=/usr/bin/python3

and then -

source .zshrc
0

If you are using Oh-My-ZSH Plugin you need to manually edit your .zshrc file.

ADD the below line:

export CLOUDSDK_PYTHON="/usr/bin/python3"

Under:

source $ZSH/oh-my-zsh.sh

Save your .zshrc file and restart your Shell to see the changes reflected. See below example

TH-C013
  • 9
  • 2
  • Isn't this the same as the other answer? – Anton Krug May 02 '21 at 02:29
  • @anton-krug Just `source .zshrc` will only persist the change for that particular shell session. Need to manually edit the `.zshrc` file for the changes to persist for every other shell sessions. – TH-C013 May 02 '21 at 22:39
  • Oh, you are right. When you will have enough reputation then these are best put into the comments to existing answers/questions instead of making separate answers. – Anton Krug May 02 '21 at 23:37