编译安装python3.6的步骤
1.下载python3源码包
wget https://www.python.org/ftp/python/3.6.6/Python-3.6.6.tgz
2.下载python3编译的依赖包
yum install -y 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
3.解压缩源码包
tar -zxvf Python-3.6.6.tgz
4.进入源码包文件夹
cd Python-3.6.6
5.编译且安装
./configure --prefix=/opt/python36 # 指定安装目录为/opt/python36
4.编译
make # 相当于把源码包里面的代码编译成linux服务器可以识别的代码
5.编译安装,此步才会最终生成 /opt/python36/
make install
注意: 第4步和第5步可以合并执行, 但是中间需要用&&隔开
make && make install # 先进行make,执行完成之后,才开始执行make install
进入/opt目录查看python36文件夹,我们要的python3都在这里了
/opt/python36/bin/python3
/opt/python36/bin/pip3
.....
6.更改linux的path变量,添加python3
vi .bash_profile
export PYTHON_HOME=/opt/python36
export PATH=$PYTHON_HOME/bin:$PATH
7. 为了永久生效path设置,添加到/etc/profile全局环境变量配置文件中 重载配置文件/etc/profile
source .bash_profile
8 .进入pyhon3
python3
9、不想每次输入python3的话,可以加个软连接
mv /usr/bin/python /usr/bin/python.bak
ln -s /usr/local/bin/python3 /usr/bin/python
接着默认pip也是需要修改的,可以通过find / -name 'pip3'找到pip3的位置,同样的,加一条软链到bin里面:
mv /usr/bin/pip /usr/bin/pip.bak
ln -s /usr/local/bin/pip3 /usr/bin/pip