skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

    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


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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search