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

0. Dependency installation

yum -y update
yum install epel-release
yum install sqlite-devel
yum install -y zlib-devel.x86_64
yum install -y openssl-devel.x86_64

 

1. Upgrade Python

The default installed Python of the system is 2.6.6, we need to upgrade to Python 2.7, use the wget command to download the source file from the official, and then unzip it to compile

wget http://www.python.org/ftp/python/2.7.10/Python-2.7.10.tar.xz
unxz Python-2.7.10.tar.xz
tar -vxf Python-2.7.10.tar

 

After executing the above command, the folder of Python-2.7.10 will be decompressed, enter the directory and execute the following command to configure

./configure --enable-shared --enable-loadable-sqlite-extensions --with-zlib

 

Where --enable-loadable-sqlite-extensions is the extension of sqlite, bring this option if you need to use it.

 

execute after

vi ./Modules/Setup

 

Find #zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz uncomment and save, then compile and install

 

make && make install

 

After installing Python 2.7, we need to back up Python 2.6 first, and then modify the yum configuration. If this step is not performed, executing the yum command will prompt you that the version of Python is incorrect.

 

Execute the following commands to make a backup of Python2.6, and then create a soft link for Python2.7

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

 

Then edit /usr/bin/yum and change #!/usr/bin/python in the first line to #!/usr/bin/python2.6.6

Now executing the yum command no longer appears the previous error message.

 

We execute python -V to view version information, if there is an error

 

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

 

Edit configuration file

 

vi /etc/ld.so.conf

Add a new line to /usr/local/lib, save and exit, then

/sbin/ldconfig  
/sbin/ldconfig -v

 

2. Install pip

 

Download the latest version of pip and install

wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py

 

Find the location of pip

whereis pip

 

Find the path of pip2.7 and create a soft chain for it as the default startup version of the system

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

 

pip is installed, now you can use it to download and install various packages

 

Attached is get-pip.py

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326270117&siteId=291194637
Recommended