CentOS7下安装Python3和PIP3

时间:2023-12-26 22:32:49

为了方便以后编译,所以整合了下配置流程

先查看是否安装了Python3

python3 -V

如果没有安装,则先安装依赖包

yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make

从官网下载Python3(具体版本可以根据个人需要修改),解压编译和安装

wget https://www.python.org/ftp/python/3.6.2/Python-3.6.2.tar.xz
tar -xvJf Python-3.6..tar.xz
cd Python-3.6.
./configure prefix=/usr/local/python3
make && make install

添加软链

ln -s /usr/local/python3/bin/python3 /usr/bin/python3

查看是否安装成功

python3 -V

将依赖修改为Python2

vim /usr/bin/yum
将第一行#! /usr/bin/python修改为#! /usr/bin/python2
保存并退出
vim /usr/libexec/urlgrabber-ext-down
将第一行#! /usr/bin/python 修改为#! /usr/bin/python2
保存并退出

安装PIP3

yum -y install epel-release
yum install python3-pip

添加软链

ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

查看软链

ll python*

安装完成

批量更新库可以使用pip-review

pip3 install pip-review
pip-review --local --interactive
若安装某些库时报错缺少Python.h,则
sudo yum install python36-devel

生成requirements

pip3 freeze > requirements.txt
pipreqs /home/project/location

使用requirements

pip3 install -r requirements.txt

感谢以下GEEKS:

linux-Centos7安装python3并与python2共存

https://www.cnblogs.com/JahanGu/p/7452527.html

更新时间:2019.10.09