Linux教程

linux 下python2升级python3 ---NEW

本文主要是介绍linux 下python2升级python3 ---NEW,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

配置Python3.6.9环境

安装依赖包

yum -y install wget openssl openssl-devel gcc gcc-c++

下载包

wget https://www.python.org/ftp/python/3.6.9/Python-3.6.9.tgz

安装

mkdir -p /usr/local/python
tar xf Python-3.6.9.tgz
cd Python-3.6.9
./configure --prefix=/usr/local/python --with-openssl
make && make install

配置

mv /usr/bin/python /usr/bin/python_old
ln -s /usr/local/python/bin/python3 /usr/bin/python
ln -s /usr/local/python/bin/pip3 /usr/bin/pip
pip install --upgrade pip

注意,所有依赖python2的脚本或者命令,需要更改为python2.7,因为现在默认的python版本为3.6,例如

sed -i '1s/python/python2.7/g' /usr/bin/yum
sed -i '1s/python/python2.7/g' /usr/libexec/urlgrabber-ext-down

验证

$ python -V
    Python 3.6.9
$ pip -V 
	pip 19.3 from /usr/local/python/lib/python3.6/site-packages/pip (python 3.6)
这篇关于linux 下python2升级python3 ---NEW的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!