1、yum安装依赖包 避免后面出现少包的问题
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 mysql-devel
2、下载安装包到一个目录下,可以是家目录,看自己喜欢
wget下载python版本 https://www.python.org/ftp/python/ 找到 Python-3.6.8.tgz包
也可以下载tgz包后上传到linux上,这是是上传的
注:外网可能无法进入,可以用淘宝镜像:http://npm.taobao.org/mirrors/python
3、解压tar -xvf Python-3.6.8.tgz
4、进入解压后的目录,若没有安装gcc 需安装。(编译安装前需要安装编译器yum install gcc)
(1)安装gcc
输入命令 yum install gcc,确认下载安装输入“y”
(2)若3.7版本之后需要一个新的包libffi-devel
安装即可:yum install libffi-devel -y
5、进入Python-3.6.8:cd Python-3.6.8执行:
(1)./configure --prefix=/usr/local/python3
(2)编译:make
(3)编译成功后,编译安装:make install
6.建立Python3和pip3的软链:
ln -s /usr/local/python3/bin/python3 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3
7.并将/usr/local/python3/bin加入PATH
(1)vim /etc/profile
(2)按“i”,然后贴上下面内容:
# vim ~/.bash_profile
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH
(3)按ESC,输入:wq回车退出。
(4)修改完记得执行行下面的命令,让上一步的修改生效:
source ~/.bash_profile
8.检查Python3及pip3是否正常可用:
python3 -V
pip3 -V