linux安装python3

1. 安装依赖环境

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

在这里插入图片描述
2. 下载python3

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

在这里插入图片描述
3. 安装python3

创建安装目录

 mkdir -p /usr/local/python3

解压

tar -zxvf Python-3.7.1.tgz

安装gcc

yum install gcc

3.7版本之后需要一个新的包libffi-devel

yum install libffi-devel -y

进入python文件夹,生成编译脚本

./configure --prefix=/usr/local/python3 
make
make install

检查python3.7编译器

/usr/local/python3/bin/python3.7

建立Python3和pip3的软链

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

4. 加入环境变量

 vim /etc/profile
if [ -f ~/.bashrc ]; then

. ~/.bashrc

fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin:/usr/local/python3/bin

export PATH

使环境变量生效

source ~/.bash_profile

5. 测试

python3 -V

pip3 -V
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页