安装Python3.6.4
1 安装python3.6可能使用的依赖
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc gcc-c++ openssl-devel
2 到python官网找到下载路径, 用wget下载
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
3 解压tgz包
tar -xf Python-3.6.5.tgz
4 进入python目录
cd /Python-3.6.5/
5 编译,安装
5.1 提示找不到SSL模块
python安装完毕后,提示找不到ssl模块:
[root@localhost ~]# python2.7.5Python 2.7.5 (default, Jun 3 2013, 11:08:43) [GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import sslTraceback (most recent call last):File "<stdin>", line 1, in <module>File "/usr/local/python27/lib/python2.7/ssl.py", line 60, in <module>import _ssl # if we can't import it, let the error propagateImportError: No module named _ssl>>>
5.2 重新编译python(去掉最后4行的注释)
#修改Setup文件vi /root/Python-3.6.5/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
5.3 编译安装
./configure --prefix=/usr/local/pythonmakemake install
5.4 测试,已可正常使用。
[root@localhost ~]# pythonPython 3.6.4 (default, Jun 3 2013, 14:56:13) [GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import ssl>>>
注:如需保留旧版本的就不需要执行 6 .7两部
6 重命名旧版本的python依赖
ll /usr/bin | grep pythonmv /usr/bin/python /usr/bin/python2.7
7 删除旧的软链接,创建新的软链接到最新的python
rm -rf /usr/bin/pythonln -s /usr/local/bin/python3.6 /usr/bin/pythonpython -V
使用yum命令报错File "/usr/bin/yum", line 30 except KeyboardInterrupt, e:
问题出现原因:
yum包管理是使用python2.x写的,将python2.x升级到python3.1.3以后,由于python版本语法兼容性导致问题出现
解决办法:
修改yum配置文件,将python版本指向以前的旧版本
# vi /usr/bin/yum#!/usr/bin/python2.7
修改urlgrabber-ext-down文件,更改python版本
# vi /usr/libexec/urlgrabber-ext-down#!/usr/bin/python2.7
Could not fetch URL https://pypi.python.org/simple/six/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
如需安装pip
下载相关文件
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
执行
/usr/local/python/bin/python3 get-pip.py
添加环境变量
vim ~/.bash_profile
添加下面这条参数
export PATH=/usr/local/python/bin:$PATH
保存
source ~/.bash_profile
测试
执行
[root@huo ~]# python3Python 3.6.5 (default, Apr 1 2018, 20:41:34)[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linuxType "help", "copyright", "credits" or "license" for more information.>>>
执行脚本如下:
vim install_python.sh
#!/bin/bashecho "正在安装相关组件"yum install -y openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc-c++ gcc openssl-develecho "下载安装包"wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgzecho "正在解压安装包"tar -xf Python-3.6.5.tgz -C /root/ && cd /root/Python-3.6.5/echo "添加ssl支持"cat >> /root/Python-3.6.5/Modules/Setup.dist <<"EOF"_socket socketmodule.cSSL=/usr/local/ssl_ssl _ssl.c \-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \-L$(SSL)/lib -lssl -lcryptoEOFecho "正在编译安装Python"./configure --prefix=/usr/local/python && make && make installcd /rootecho "删除安装包"rm -rf /root/Python-3.6.5.tgz && rm -rf /root/Python-3.6.5echo "正在添加环境变量"echo "export PATH=/usr/local/python/bin:$PATH">> ~/.bash_profilesource ~/.bash_profileecho "安装完成,请执行python3进行测试"
点击查看更多内容
为 TA 点赞
评论
共同学习,写下你的评论
评论加载中...
作者其他优质文章
正在加载中
感谢您的支持,我会继续努力的~
扫码打赏,你说多少就多少
赞赏金额会直接到老师账户
支付方式
打开微信扫一扫,即可进行扫码打赏哦