ubuntu16.04升级python3.7.1教程
-
准备
sudo apt-get install --reinstall zlibc zlib1g zlib1g-dev sudo apt-get install libffi-dev libssl-dev libreadline-dev -y
-
安装
使用python官方站点的以下命令下载Python。您也可以下载最新版本代替下面指定的版本
#下载python3.7.1 sudo wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz #解压 sudo tar xzf Python-3.7.1.tgz
-
进入解压目录
cd Python-3.7.1/
-
4、建立安装的目录
sudo mkdir -p /usr/local/python3
-
编译安装
#执行这步是后面最好加上 --enable-optimizations 会自动安装pip3及优化配置 #./configure:配置安装环境 #--prefix=/usr/local/python3:指向安装路径 #--enable-optimizations:安装pip3及优化配置 ./configure --prefix=/usr/local/python3 --enable-optimizations make sudo make install
-
删除软连接
> #先执行查看版本,如果有则证明软链接已存在,需要先删去以前的再重新建立 > #这里表明我已有python3的软链接而没有pip3的软链接所以需要删除python3的软链接重新建立 > jianjiacheng@J-computer:~/Python-3.7.1$ python3 -V > Python 3.5.2 > jianjiacheng@J-computer:~$ pip3 -V > bash: /usr/lib/command-not-found:/usr/bin/python3: bad interpreter: No such file or directory > apt install python3-pip > rm -rf /usr/bin/python3 > rm -rf /usr/bin/pip3
-
建立新的指向python3.7的软链接
添加python3的软链接
ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3
添加 pip3 的软链接
ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip3
-
检测版本
jianjiacheng@J-computer:~$ python3 -V
Python 3.7.1jianjiacheng@J-computer:~$ pip3 -V
pip 10.0.1 from /usr/local/python3/lib/python3.7/site-packages/pip (python 3.7) -
复制‘lsb_release.py’模块
将其复制到设置python3.7的系统模块加载位置,也就是报错处subprocess.py所在的目录
sudo cp /usr/lib/python3/dist-packages/lsb_release.py /usr/local/python3/lib/python3.7/
-
缺少‘lsb_release.py’模块:
[【问题解决】subprocess.CalledProcessError: Command ‘(‘lsb_release‘, ‘-a‘)‘ returned non-zero exit status 1][1]
[1]: https://blog.csdn.net/p1279030826/article/details/111573774