如何安装指定版本的py

 



查看当前的python版本

python --version

python3 --version


装git

yum update -y && yum install git -y

apt update -y && apt install git -y

apk update && apk add git


下载pyenv管理

curl https://pyenv.run | bash



编辑变量文件

nano ~/.bashrc



添加pyenv的变量

export PYENV_ROOT="$HOME/.pyenv"

if [[ -d "$PYENV_ROOT/bin" ]]; then

  export PATH="$PYENV_ROOT/bin:$PATH"

fi

eval "$(pyenv init --path)"

eval "$(pyenv init -)"

eval "$(pyenv virtualenv-init -)"


重新加载bashrc

source ~/.bashrc




查看pyenv的版本

pyenv --version


安装依赖

# CentOS

yum groupinstall "Development Tools" -y

yum install openssl-devel bzip2-devel libffi-devel ncurses-devel zlib-devel readline-devel sqlite-devel xz-devel findutils -y


curl -O https://www.openssl.org/source/openssl-1.1.1u.tar.gz
tar -xzf openssl-1.1.1u.tar.gz
cd openssl-1.1.1u
./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl shared zlib
make
make install
echo "/usr/local/openssl/lib" > /etc/ld.so.conf.d/openssl-1.1.1u.conf
ldconfig -v
cd ..

export LDFLAGS="-L/usr/local/openssl/lib"
export CPPFLAGS="-I/usr/local/openssl/include"
export PKG_CONFIG_PATH="/usr/local/openssl/lib/pkgconfig"




# Ubuntu/Debian

apt install build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev xz-utils tk-dev libffi-dev liblzma-dev libgdbm-dev libnss3-dev libedit-dev -y



# Alpine Linux

apk add --no-cache bash gcc musl-dev libffi-dev openssl-dev bzip2-dev zlib-dev readline-dev sqlite-dev libc6-compat linux-headers make xz-dev build-base  ncurses-dev 




查看可以安装的版本

pyenv install --list


安装对应版本

pyenv install 3.12.4


全局应用对应版本

pyenv global 3.12.4


查看当前的python版本

python --version

python3 --version



删除所有版本

for version in $(pyenv versions --bare); do pyenv uninstall -f $version; done






















评论

此博客中的热门博文

科技lion官方一键脚本上线!VPS监控测试建站维护于一身的全能工具箱

CloudCone付费VPS分享 挺便宜的

新机到手我必做的10件事?让VPS飞速运行更安全!