Python3 version

140 views
Skip to first unread message

jeevan kota

unread,
Jul 15, 2021, 6:30:49 PM7/15/21
to gce-discussion
How can I set Python3 as the default version in  google cloud shell. Actually showing python2.

Fady (Google Cloud Platform)

unread,
Jul 19, 2021, 12:16:06 PM7/19/21
to gce-discussion
CloudShell seems to be using Python version 2.7 as a default command line interpreter. This might be due to some Cloud SDK tools that are still reliant on version 2.7 as explained in this document:"Other Python tools shipped in the Cloud SDK do not support Python 3 and require Python 2.7.x, including: dev_appserver endpointscfg". 

Though looking at the Cloud SDK ( version 348.0.0) configs in cloudshell  , it seems that it is already using version 3 :

gcloud info | grep Python
Python Version: [3.7.3 (default, Jan 22 2021, 20:04:44)  [GCC 8.3.0]]
Python Location: [/usr/bin/python3]
Python PATH: [/usr/bin/../lib/google-cloud-sdk/lib/third_party:/usr/lib/google-cloud-sdk/lib:/usr/lib/python37.zip:/usr/lib/python3.7:/usr/lib/python3.7/lib-dynload]

On this front, I suggest reporting a feature request on issuetracker to update the tools and make version 3 a default for CloudShell. 

Answering your question and as CloudShell  (which is based on Debian Linux ) already includes Python version 3, you can point the symlink to it. I found this third party article that can help. As per the same article you can also switch between versions if needed. 

Example of configuring Python 3 as a priority "1" (notice trailing 1 at the end of  "update-alternative" command below) :

$ ls /usr/bin/python*
/usr/bin/python /usr/bin/python2 /usr/bin/python2.7 /usr/bin/python2.7-config /usr/bin/python3 /usr/bin/python3.7 /usr/bin/python3.7-config /usr/bin/python3.7m /usr/bin/python3.7m-config /usr/bin/python3m
$ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 1
update-alternatives: using /usr/bin/python3.7 to provide /usr/bin/python (python) in auto mode
$ python --version
********************************************************************************
Python 2 is deprecated. Upgrade to Python 3 as soon as possible.
See https://cloud.google.com/python/docs/python2-sunset
To suppress this warning, create an empty ~/.cloudshell/no-python-warning file.
The command will automatically proceed in seconds or on any key.
********************************************************************************
Python 3.7.3

If you need further help with the current config, I suggest posting on Stack Exchange as you have a larger community of Linux experts that can assist with Linux workarounds. I hope the above is helpful.
Reply all
Reply to author
Forward
0 new messages