Upgrade Python2.6 to Python2.7 in CentOS 6. X, python2.6python2.7
Step 1: Upgrade python
The default Python version installed in CentOs 6. x is 2.6.x. to upgrade to Python2.7.x, download the source file from the official website, decompress and compile the file.
wget http://www.python.org/ftp/python/2.7.10/Python-2.7.10.tar.xzunxz Python-2.7.10.tar.xztar -vxf Python-2.7.10.tar
After running the preceding command, decompress the Python-2.7.10 folder, enter the directory, and execute the following command to configure
./configure --enable-shared --enable-loadable-sqlite-extensions --with-zlib
Where--enable-loadable-sqlite-extensionsIt is an extension of sqlite. This option is included if needed.
You need to modify the Setup file before compilation, and remove the comments of zlib required for compilation.
vi ./Modules/Setup
Find#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lzRemove comments and save them, and then compile and install them.
make && make install
After installing Python2.7, we need to back up Python2.6 and then modify the yum configuration. If this step is not performed, running the yum command will prompt you that your Python version is incorrect. Run the following command to back up Python2.6 and then create a soft link for Python2.7:
mv /usr/bin/python /usr/bin/python2.6.6ln -s /usr/local/bin/python2.7 /usr/bin/python
Edit/usr/bin/yum#!/usr/bin/pythonModify#!/usr/bin/python2.6.6
The preceding error message is no longer displayed when you run the yum command. Run python-V to view 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
vi /etc/ld.so.conf
Add a new line of content/usr/local/lib, Save and exit, and then
/sbin/ldconfig /sbin/ldconfig -v
Step 2: Install pip
Download the latest pip version, and then install
wget https://bootstrap.pypa.io/get-pip.pypython get-pip.py
Locate 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 has been installed. Now you can use it to install various required packages :)
Step 3: Install scrapy
Directpip install scrapy OK.
Summary
The above are all the steps for upgrading from Python2.6 to Python2.7 in CentOS 6. X. Have you learned this? I hope this article will help you in your study or work.