Check the current version
[ root@node1 ~]# python -V
Python 2.7.5
Create installation directory (custom)
[ root@node1 Python-3.7.1]# mkdir /usr/local/python3
Download the python3 compressed package from the official website, unzip it (with 3.7.1 version as an example)
# wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz
# tar zxf Python-3.7.1.tgz
cd into the unzipped directory, then
# cd Python-3.7.1
# . /configure --prefix=/usr/local/python3/
# make && make install
cd enter/usr/bin
Among them are python, python2, python2.7 The three files point to the latter in turn.
Back up the current default version of python, and restore it if necessary:
# sudo mv python python.bak
Create python3.7 new link (you can also create a python3 command to distinguish, same as mac), so the default python version is replaced with python3.7
# ln -s /usr/local/python3/bin/python3.7/usr/bin/python
Check the current default python version
# python -v
Since yum uses python2, it cannot work normally after replacing it with python3.
So modify the yum configuration file:
# sudo vi /usr/bin/yum
Change the python version specified in the first line to python2.7:*#!/usr/bin/python to#!/usr/bin/python2.7
Modify the urlgrabber configuration file (many online tutorials miss this step)
# sudo vi /usr/libexec/urlgrabber-ext-down
Same as yum, change the python of the head to python2.7
Link: https://www.jianshu.com/p/74227d7ae6a6
After Python is installed, it prompts that the ssl module cannot be found:
(< http://blog.csdn.net/qq_25560423/article/details/62055497>;)
For example:
pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
Collecting xxx
Could not fetch URL <https://pypi.python.org/simple/xxxx/>: There was a problem confirming the ssl certificate: Can’t connect to HTTPS URL because the SSL module is not available.- skipping
Could not find a version that satisfies the requirement xxx(from versions:)
No matching distribution found for xxx
[ root@localhost ~]# python2.7.5
Python 2.7.5 (default, Jun 3 2013, 11:08:43)
[ GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
import ssl
Traceback (most recent call last):
File “”, line 1, in
File “/usr/local/python27/lib/python2.7/ssl.py”, line 60, in
import _ssl # if we can’t import it, let the error propagate
ImportError: No module named _ssl
Check the openssl installation package and found that the openssl-devel package is missing
[ root@localhost ~]# rpm -aq|grep openssl
openssl-0.9.8e-20.el5
openssl-0.9.8e-20.el5
[ root@localhost ~]#
yum install openssl-devel
[ root@localhost ~]# yum install openssl-devel -y
View installation results
[ root@localhost ~]# rpm -aq|grep openssl
openssl-0.9.8e-26.el5_9.1
openssl-0.9.8e-26.el5_9.1
openssl-devel-0.9.8e-26.el5_9.1
openssl-devel-0.9.8e-26.el5_9.1
Recompile python
Modify the Setup file
vi /usr/software/Python-2.7.5/Modules/Setup
Amend to the following:
Socket module helper forsocket(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
Recompile
make
make install
Tested, it can be used normally.
[ root@localhost ~]# python2.7.5
Python 2.7.5 (default, Jun 3 2013, 14:56:13)
[ GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
import ssl
Reinstall with pip
Recommended Posts