Details of how to upgrade Python in CentOS

  • 2020-06-12 09:33:14
  • OfStack

CentOS upgrade Python2.6 to Pythno2.7

Recently, the error of Python and ValueError: zero length field name in format occurred on Linode.

A quick review of the documentation shows that simply upgrading Python to version 2.7 or above will fix the problem.

Pythno-V 1 The current version on Centos is 2.6.

Python2.6 is the default version installed in the CentOS6 series

So we can make mistakes like this

ValueError: zero length field name in format

At this point, we need to upgrade es34EN2.6 to es35EN2.7 or above

Upgrade Python

The default installation of Python is 2.6.x, so we need to upgrade to Python2.7, download the source file from the official command wget, and then extract it for compilation


wget https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tar.xz
unxz Python-2.7.13.tar.xz
tar -vxf Python-2.7.13.tar

After executing the above command, unzip the folder Python-2.7.13, enter the directory and execute the following command to configure

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

perform

vim ./Modules/Setup

Find #zlib ES60en. c-ES62en $(prefix)/ include-ES65en $(exec_prefix)/ lib-ES69en. Uncomment and save, then compile and install

make && make install

After installing Python2.7, we need to make a backup of Python2.6

Execute the following command to back up Python2.6, then create soft links for Python2.7 and use Python2.7 as the default Python


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


Then edit /usr/bin/yum to put line 1 #! /usr/bin/python changed to #! / usr/bin/python2. 6.6

The yum command will no longer have the same error message.

We perform python-V to view the version information if an error occurs

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

Edit configuration file

vim /etc/ld.so.conf

Check whether /usr/local/lib is available. If not, please add 1 line, save and exit.

And then refresh the configuration


/sbin/ldconfig 
/sbin/ldconfig -v

PS: If you originally installed Pip in python2.6, you will need to reinstall it

PS2: You will need to reinstall the third library if you installed it with pip install xxx


Related articles: