安装依赖包
在安装Python之前需要先安装依赖包
yum install gcc patch
yum install libffi-devel
yum install python-devel
yum install zlib-devel
yum install bzip2-devel
yum install openssl-devel
yum install ncurses-devel
yum install sqlite-devel
yum install readline-devel
yum install tk-devel
yum install gdbm-devel
yum install db4-devel
yum install libpcap-devel
yum install xz-devel -y
或者
yum install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel -y
下载 python 源码包
在官网 https://www.python.org/downloads/source/ 下载Gzipped source tarball 的源码包
或者通过 wget命令进行下载 wget https://www.python.org/ftp/python/3.5.7/Python-3.5.7.tgz
解压文件
tar -xvzf Python-3.5.1.tgz
配置编译并安装
首先cd到解压目录下
./configure --prefix=/usr/local/python3
make
make install
警告
make install
可以覆盖或伪装 python3
二进制文件。因此,建议使用 make altinstall
而不是 make install
,因为后者只安装了 exec_prefix/bin/pythonversion
添加环境变量
vim /etc/profile
添加 /usr/local/python3/bin
export PATH="/usr/local/nginx/sbin/:/usr/local/python3/bin:$PATH"
source /etc/profile
或者参加软链接
ln -s pip3.5 /usr/local/bin/pip3
ln -s python3.5 /usr/local/bin/python3
在/etc/profile下配置好环境变量后,每次关闭shell窗口后都需要再执行一次source /etc/profile
才能生效,这个问题需要在~/.bashrc
文件最后添加source /etc/profile
,这样问题便得到解决
大功告成
更多分享,请关注微信公众号