1:安装Python可能需要的依赖
[root@cdh08 load]# yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc gcc-c++
2:查看python 版本
[root@cdh02 ~]# python -V
Python 2.7.5
[root@cdh02 ~]#
3:下载Python3.6.5 压缩包
[root@cdh02 datax]# wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
也可以单独下载后上传
4:使用root权限打开终端,进行解压缩操作:
[root@cdh08 load]# tar -zxvf Python-3.6.5.tgz
5:对安装包目录进行重命名:
[root@cdh08 load]# mv Python-3.6.5 python3.6
6:移动python目录到/usr/lib64/下
[root@cdh08 load]# mv python3.6 /usr/lib64/
7:修改Setup文件,启动ssl模块:
[root@cdh08 python3.6]# vim /usr/lib64/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
8: 编译安装包,指定安装目录,进入python3.6目录,执行
进入python3.6目录
[root@cdh08 python3.6]# cd /usr/lib64/python3.6
先安装xz-devel
[root@cdh08 python3.6]# yum install -y xz-devel
指定安装目录(prefix=/usr/lib64/python3.6为python的真正安装目录)
[root@cdh08 python3.6]#./configure --with-ssl --prefix=//usr/lib64/python3.6
确认无误后,进入安装目录,执行编译与安装(make check 或 make test 可对软件进行测试)
[root@cdh08 python3.6]# make && make install
将原来的链接备份
[root@cdh08 python3.6]# mv /usr/bin/python /usr/bin/python.bak
新建软连接,指向新安装的python3.6.5
[root@cdh08 python3.6]# ln -s /usr/lib64/python3.6/bin/python3.6 /usr/bin/python
9: 更改yum配置(yum用到python2才能执行,否则会导致命令不能正常使用)
[root@cdh08 python3.6]# vi /usr/bin/yum
把 #! /usr/bin/python
修改为:#! /usr/bin/python2
[root@cdh08 python3.6]# vi /usr/libexec/urlgrabber-ext-down
把 #! /usr/bin/python
修改为:#! /usr/bin/python2
10 :验证是否可用全局可用
[root@cdh08 python3.6]# python -V
Python 3.6.5
[root@cdh08 python3.6]#
11: 配置pip:
11.1:Python3.6.5是自带了pip,我们可以进入python3.6的bin目录下进行查看你所安装的Python版本是否自带pip。
[root@shuqi3 python3.6]# ls /usr/lib64/python3.6/bin
11.2 将原来的pip备份
[root@shuqi3 python3.6]# mv /usr/bin/pip pip.bak
11.3 创建一个软连接指向python的pip(一定要指向pip3,其他的还是会报错)
[root@shuqi3 python3.6]# ln -s /usr/lib64/python3.6/bin/pip3 /usr/bin/pip
11.4 :检查pip版本(注:正常情况pip版本9.0.3)
[root@cdh08 python3.6]# pip -V
pip 9.0.3 from /opt/python3.6/lib/python3.6/site-packages/pip (python 3.6)
11.5: 旧版可能会提示pip版本不匹配,需要更新,执行更新命令
[root@shuqi3 site-packages]# pip install --upgrade pip
11.6:检查更新后pip版本
[root@shuqi3 site-packages]# pip -V
pip 21.3.1 from /usr/lib64/python3.6/lib/python3.6/site-packages/pip (python 3.6)
11.7: 配置清华源(下载速度更快)
[root@shuqi32 python3.6]# pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
Writing to /root/.config/pip/pip.conf
11.8 安装其他的包
[root@shuqi32 python3.6]# cd /usr/lib64/python3.6/lib/python3.6/site-packages/
[root@shuqi32 site-packages]# pip install pandas
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pandas
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c3/e2/00cacecafbab071c787019f00ad84ca3185952f6bb9bca9550ed83870d4d/pandas-1.1.5-cp36-cp36m-manylinux1_x86_64.whl (9.5 MB)
|████████████████████████████████| 9.5 MB 5.8 MB/s