centos7.2上安装python3和pip19.0.3
安装libressl
下载地址: https://ftp.openbsd.org/pub/OpenBSD/LibreSSL/libressl-2.7.4.tar.gz
或者 :https://pan.baidu.com/s/1zZSPmERAvkEU4-ggj-wpgA
提取码:zusy
cd libressl-2.7.4 ./configure --prefix=/usr/local make make install
libressl代替openssl
vim /etc/ld.so.conf.d/local.conf #新建local.conf文件,添加下面一行 /usr/local/lib # 将 /usr/local/lib 目录加入到模块加载目录。 ldconfig -v #重新加载共享模块: openssl version #查看版本
安装python3.7
下载链接:https://pan.baidu.com/s/1zZSPmERAvkEU4-ggj-wpgA
提取码:zusy
让python使用libressl ,修改如下源码包中Setup.dist文件,取消如下注释:
cd /usr/src/Python-3.7.3 ./configure --prefix=/usr/local/python make make install
vim /usr/src/Python-3.7.3/Modules/Setup.dist #_socket socketmodule.c #SSL=/usr/local #libressl的安装目录 #_ssl _ssl.c \ #-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \ #-L$(SSL)/lib -lssl -lcrypto
修改默认的python版本
rm -rf /usr/bin/python #删除/usr/bin下面python2的超链接 ln -s /usr/local/python/bin/* /usr/bin/ ln -s /usr/bin/python3.7 /usr/bin/python
修改下面内容,否则无法使用yum
vim /usr/bin/yum #!/usr/bin/python ==> #!/usr/bin/python2.7 vi /usr/libexec/urlgrabber-ext-down #!/usr/bin/python ==> #!/usr/bin/python2.7
如果不修改urlgrabber-ext-down文件,用yum安装软件时会出现下面的情况:
Error downloading packages: net-tools-2.0-0.24.20131004git.el7.x86_64: [Errno 5] [Errno 2] No such file or directory
检测libressl和python3.7
[root@localhost pip-19.0.3]# ldd /usr/local/python/bin/python3 | fgrep ssl libssl.so.45 => /usr/local/lib/libssl.so.45 (0x00007f0636fe3000) [root@localhost pip-19.0.3]# python Python 3.7.3 (default, Apr 5 2019, 02:28:57) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import ssl >>>
安装pip-19.0.3
[root@localhost src]# cd pip-19.0.3/ [root@localhost pip-19.0.3]# python -V Python 3.7.3 [root@localhost pip-19.0.3]# python setup.py install [root@localhost ~]# ln -s /usr/local/python/bin/pip* /usr/bin/ [root@localhost ~]# ls /usr/bin/pip* -l lrwxrwxrwx 1 root root 25 Apr 5 03:08 /usr/bin/pip -> /usr/local/python/bin/pip lrwxrwxrwx 1 root root 26 Apr 5 03:08 /usr/bin/pip3 -> /usr/local/python/bin/pip3 lrwxrwxrwx 1 root root 28 Apr 5 03:08 /usr/bin/pip3.7 -> /usr/local/python/bin/pip3.7
重启电脑后才能使用pip install xx: