CentOS 6 compile and install python 3
Python official website: https://www.python.org/
1. Check the CentOS version and the system default Python version:
cat /etc/redhat-release
python -V
**2. Compile and install Python-3.6.1: **
1、 Install dependent packages:
yum -y groupinstall "Development tools"
yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-develreadline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
2、 Set the current system time of CentOS6:
date 040413022017.30
date
3、 Compile and install Python-3.6.1:
wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tar.xz
tar xf Python-3.6.1.tar.xz -C /usr/src
cd /usr/src/Python-3.6.1
. /configure --prefix=/usr/local/python3.6.1 --enable-shared --enable-profiling--enable-optimizations --disable-ipv6 --with-threads --with-pymalloc --with-fpectl--enable-loadable-sqlite-extensions
make && make install //In this step, a test needs to be performed, which takes a long time
4、 Change the default Python version of CentOS6 to 3.6.1:
mv /usr/bin/python /usr/bin/python2.6.6-old
ln -s /usr/local/python3.6.1/bin/python3 /usr/bin/python
5、 Add to the PATH environment variable:
vim /etc/profile.d/python3.6.1.sh
exportPATH=/usr/local/python3.6.1/bin:$PATH
. /etc/profile.d/python3.6.1.sh
echo $PATH
6、 Configuration header file:
ln -sv /usr/local/python3.6.1/include /usr/include/python3.6
7、 Configuration library file:
echo "/usr/local/python3.6.1/lib" >/etc/ld.so.conf.d/python3.6.1.conf
cat /etc/ld.so.conf.d/python3.6.1.conf
ldconfig
8、 Configure man help files:
vim /etc/man.config, add the following code:
MANPATH /usr/local/python3.6.1/share/man
9、 View the configured Python version:
python -V
python3 -V
3. Modify the Python version in yum to the original 2.6.6 version of the system:
After upgrading Python, yum cannot be used:
vim /usr/bin/yum, modify the "#!/usr/bin/python" in the first line to "#!/usr/bin/python2.6.6-old"
Added: install pip method
First install the epel extension source:
# yum -y install epel-release
Then install pip
yum -y install python-pip
centos find command
find /-name "pip*"
1、 Install python3.6.1
2、 Install setuptools35.0.2
3、 Install pip
easy_install pip
This article is from the "天道救勤" blog, please keep this source http://qiuyue.blog.51cto.com/1246073/1912806