一、安装python
1、安装python的依赖项
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc gcc-c++
2、下载python3.6版本
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
#解压
tar -zxvf Python-3.6.5.tgz
3、重命名并移动
mv Python-3.6.5 python3.6
mv /python3.6 /opt/
4、修改setup文件,启动ssl模块
vi /opt/python3.6/Modules/Setup.dist
更改文件内容
# Socket module helper for socket(2)
#_socket socketmodule.c timemodule.c
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
#_ssl _ssl.c \
#-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
#-L$(SSL)/lib -lssl -lcrypto
为以下内容:
# Socket module helper for socket(2)
_socket socketmodule.c timemodule.c
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
5、编译安装包
编译过程最好每一步确认,是否做好
cd /opt/python3.6
./configure --with-ssl --prefix=/opt/python3.6
make && make install
将原来的链接备份
mv /usr/bin/python /usr/bin/python.bak
新建软连接,指向新安装的python3.6.5
ln -s /opt/python3.6/bin/python3.6 /usr/bin/python
6、更改yum配置(yum用到python2才能执行,否则会导致命令不能正常使用)
vi /usr/bin/yum
把 #! /usr/bin/python
修改为:#! /usr/bin/python2
vi /usr/libexec/urlgrabber-ext-down
把 #! /usr/bin/python
修改为:#! /usr/bin/python2
7、验证是否可用
[root@ayaka ~]# python -V
Python 3.6.5
二、配置pip
1:Python3.6.5是自带了pip,我们可以进入python3.6的bin目录下进行查看你所安装的Python版本是否自带pip。
[root@localhost bin]# ls /opt/python3.6/bin/
2:创建一个软连接指向python的pip(一定要指向pip3,其他的还是会报错)
ln -s /opt/python3.6/bin/pip3 /usr/bin/pip
3:检查pip版本(注:正常情况pip版本9.0.3,此处更新过)
[root@localhost bin]# pip -V
pip 21.3.1 from /opt/python3.6/lib/python3.6/site-packages/pip (python 3.6)
4:旧版可能会提示pip版本不匹配,需要更新,执行更新命令
pip install --upgrade pip
5:检查更新后pip版本
[root@localhost bin]# pip -V
pip 21.3.1 from /opt/python3.6/lib/python3.6/site-packages/pip (python 3.6)
PS:配置清华源(下载速度更快)
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
更新完成后,可正常使用pip安装模块了!