简体   繁体   English

在 Google Cloud Shell 中更新到 python 3.10

[英]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.我想在我的谷歌云 shell 中升级到 python 3.10,但我没有这样做。 I found two methods online, which were unsuccessful so far.我在网上找到了两种方法,目前都不成功。

  1. Using the deadsnakes repo : I tried the following commands:使用 deadsnakes 存储库:我尝试了以下命令:
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.但我收到一个错误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.我能够安装 python 3.10。 But when my Google Cloud Shell restarts, I am unable to run python3.10.但是当我的 Google Cloud Shell 重新启动时,我无法运行 python3.10。 It states -bash: python3.10: command not found .它指出-bash: python3.10: command not found

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. 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 toCustomize Cloud Shell container images and Environment customization.请参阅此文档以自定义 Cloud Shell 容器映像环境自定义。

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

This worked out for me.这对我有用。 The default python version remained 3.10.7 even after the shell restarted.即使在 shell 重新启动后,默认的 python 版本仍然是 3.10.7。

# 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.感谢@ali-khorso 和@yungchin。 Link to the post 链接到帖子

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM