CentOS method of installing Python2.7 and Python2.6

  • 2020-06-19 12:17:18
  • OfStack

Recently, I bought VPS to use CentOS service system. In the past, Linux was quite good when I used Ubuntu, but these days when I used CentOS, I have a new understanding of Linux. Linux can also drive you crazy! I installed Python2.7 in the original system after a variety of problems, a variety of libraries can not find ah! Because many of the libraries in ContOS rely on Python2.6, various problems will occur after installing Python2.7. If you can make the two versions coexist well, you can solve this problem. Later, I found a blog that solved my problem, and now it also points out a direction for others who have the same problem as me.

Start by updating yum and installing the development toolset


yum -y update
yum groupinstall -y 'development tools'

Then install the package required by the python tool (otherwise installing setuptools and pip will make an error and prompt you to find what files are missing, so install ahead of time).


yum install -y zlib-devel bzip2-devel openssl-devel xz-libs wget

Install Python2.7 with source code


//  Download the source code 
wget http://www.python.org/ftp/python/2.7.13/Python-2.7.13.tar.xz
//  Unzip the files 
xz -d Python-2.7.13.tar.xz
tar -xvf Python-2.7.13.tar

//  Go to the unzipped folder 
cd Python-2.7.13
//  Run the configure 
./configure --prefix=/usr/local
//  Compile and install 
make
make altinstall

Maybe what you see elsewhere is make install, but Here I'm using make altinstall. Because altinstall does not affect the original VERSION of python.

Set up soft connection


ln -s /usr/local/bin/python2.7 /usr/bin/python

When we use the python command after the soft connection, it's time to point to our version 2.7 python.

Install setuptools


//  Download the source code 
wget --no-check-certificate https://pypi.python.org/packages/source/s/setuptools/setuptools-1.4.2.tar.gz
//  Unzip the files 
tar -xvf setuptools-1.4.2.tar.gz
//  Go to the unzipped folder 
cd setuptools-1.4.2
//  The installation 
python2.7 setup.py install

Install pip


curl https://bootstrap.pypa.io/get-pip.py | python2.7

Solve the problem of yum not working

Since yum does not support pthon2.7 after the above steps, you will find that yum is not available. python 2.6 was not removed during the installation, so we only specify python version for yum


//  Open with the editor yum
vi /usr/bin/yum

Put line 1 #! / usr/bin/python to #! / usr/bin/python2. 6

Now run yum under 1 and see if it works.


Related articles: