Upgrade CentOS to Python2.6 to Python2.7 and install pip

  • 2020-05-27 08:03:12
  • OfStack

Now most Centos6.x version of the system python is 2.x, now due to the development needs to install the front-end code of the build tool glue, so it is necessary to do the upgrade of python version

Upgrade python

python installed by default is 2.6.6, we need to upgrade to Python2.7

wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tar.xz 
tar xf Python-2.7.12.tar.xz
cd Python-2.7.12
./configure --enable-shared --enable-loadable-sqlite-extensions --with-zlib

Among them, enable-loadable-sqlite-extensions is an sqlite extension, which can be executed with this option if needed

vim ./Modules/Setup


#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz , remove the preceding comment "#", Then you install and compile 
make && make install

After installing Python2.7, we need to back up Python2.6, and then modify the configuration of yum. If you do not modify the yum command, you will be informed that the version of Python is not correct

mv /usr/bin/python /usr/bin/python2.6.6
ln -s /usr/local/bin/python2.7 /usr/bin/python
vim /usr/bin/yum

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

Now execute the yum command and there will be no error

python -v
error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory

The above error appears and the configuration file is edited

echo "/usr/bin/lib" >> /etc/ld.so.conf
/sbin/ldconfig -v

pip installation

cd /usr/local/src
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
whereis pip

Find the path to pip2.7 and create a soft connection for it as the default boot version of the system

ln -s /usr/local/bin/pip2.7 /usr/bin/pip

Now you can install various packages using pip

pip install glue

Related articles: