Press "Enter" to skip to content

linux centos7 安装python3和pip最新版本

Last updated on 2020-04-16

1.首先安装编译依赖包:
yum -y install wget openssl openssl-devel gcc gcc-c++
2.下载包:
wget https://www.python.org/ftp/python/3.6.9/Python-3.6.9.tgz
3.安装:

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

4.配置

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

5.注意所有依赖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

6.验证
$ python -V

Python 3.6.9

$ pip -V

pip 19.3 from /usr/local/python/lib/python3.6/site-packages/pip (python 3.6)
发表评论

电子邮件地址不会被公开。 必填项已用*标注

2 × 2 =