Linux 安装 python 指定版本--编译源码方式
自动化脚本:
1 #!/bin/bash 2 sudo apt-get update 3 4 sudo apt-get install -y gcc make 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 5 6 sudo mkdir /etc/python3.7.1 7 8 sudo wget -P /home/$USER https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz 9 10 sudo tar zxvf /home/$USER/Python-3.7.2.tgz -C /home/$USER 11 12 sudo /home/$USER/Python-3.7.2/configure --enable-optimizations --prefix=/etc/python3.7.1 13 14 sudo make 15 sudo make install 16 17 sudo apt-get -y install python-pip python-virtualenv python-dev 18 sudo virtualenv --python=/etc/python3.7.1/bin/python3 --no-site-packages --download /home/.pyenvs/myevn
根据需要修改文件中的 python 版本号,即可。
python 目录为:/etc/python3.7.1
虚拟目录为: /home/.pyenv/myenv
激活虚拟环境:source /home/.pyenvs/myenv/bin/activate
查看python 版本: python -V
退出虚拟环境:deactivate