Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update to python 3.10 in Google Cloud Shell

I want to upgrade to python 3.10 in my google cloud shell, but I failed to do so. I found two methods online, which were unsuccessful so far.

  1. Using the deadsnakes repo: I tried the following commands:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update

But I get an Error The repository 'http://ppa.launchpad.net/deadsnakes/ppa/ubuntu kinetic Release' does not have a Release file.

  1. Install from the source: I followed the tutorial in this link. I am able to install python 3.10. But when my Google Cloud Shell restarts, I am unable to run python3.10. It states -bash: python3.10: command not found.
like image 457
Cloude Avatar asked Oct 17 '25 21:10

Cloude


2 Answers

This worked out for me. The default python version remained 3.10.7 even after the shell restarted.

# install pyenv to install python on persistent home directory
curl https://pyenv.run | bash

# add to path
echo 'export PATH="$HOME/.pyenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc

# updating bashrc
source ~/.bashrc

# install python 3.10.7 and make default
pyenv install 3.10.7
pyenv global 3.10.7

# execute
python

credit to @ali-khorso and @yungchin. Link to the post

like image 186
Cloude Avatar answered Oct 20 '25 10:10

Cloude


Google Cloud Shell environment is ephemeral and reset after each session, as an alternative solution you can configure your Google Cloud Shell by creating a Docker image that functions as a custom Cloud Shell environment with your specified additional packages and custom configurations. Refer on this documentation to Customize Cloud Shell container images and Environment customization.

Additionally Google Cloud Shell is running on Debian 11, you can follow this guide on Installing Python 3.10 On Debian 11.

like image 29
かいぜん Avatar answered Oct 20 '25 12:10

かいぜん



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!