在Linux上安装Python3
https://www.cnblogs.com/lemon-feng/p/11208435.html
一、安装依赖环境
输入命令:
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
由于运行以上命令出现:Error: Unable to find a match: db4-devel libpcap-devel,即使libpcap、libpcap-devel安装成功也是报错,于是我直接跳过进行下一步操作。
可执行以下命令安装db4-devel libpcap
yum install epel-release
yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
如果还安装失败,执行以下命令
dnf --enablerepo=powertools install libpcap-devel
然后执行以下命令
yum install libffi-devel -y
二、下载Python3
1.进入opt文件目录下,cd opt/
2.下载python3 (可以到官方先看最新版本多少)
输入命令 wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz
或者已经下载,则直接上传
3.安装Python3
安装在/usr/local/python3(具体安装位置看个人喜好)
解压下载好的Python-3.x.x.tgz包(具体包名因你下载的Python具体版本不不同⽽而不不同,如:我下载的是Python3.7.1.那我这里就是Python-3.7.1.tgz)
输入命令 tar -zxvf Python-3.7.1.tgz
解压后出现python的文件夹
4、将文件移动到/usr/local
mv Python-3.6.5 /usr/local
5、创建python3目录
mkdir /usr/local/python3
6、进入解压的文件夹
cd /usr/local/Python-3.6.5
7、配置安装目录
./configure --prefix=/usr/local/python3
8、安装
make
make install
5.建立Python3和pip3的软链:
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
如果已存在,选择覆盖ln -sf /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
ln -sf /usr/local/python3/bin/pip3 /usr/bin/pip3
7.检查Python3及pip3是否正常可用:
python3 -V
pip3 -V