Method of upgrading Python2.6 to Python2.7 under CentOS 6.X system
- 2020-05-12 02:49:39
- OfStack
Step 1: upgrade python
The default version of Python installed on CentOs 6.x is 2.6.x. If you want to upgrade to Python2.7.x, download the source file from the official system, then unzip and 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, you will unzip the Python-2.7.10 folder, enter the directory and execute the following command to configure it
./configure --enable-shared --enable-loadable-sqlite-extensions --with-zlib
Among them
--enable-loadable-sqlite-extensions
Is an extension of sqlite, with this option if you need to use it.
Before compiling, we need to modify the Setup file to uncomment the zlib file we need to compile
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 Python2.7, we need to back up Python2.6, and then modify the configuration of yum. If you don't do this step, the yum command will prompt you that the Python version is not correct. Follow these commands to back up 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
, will the first row
#!/usr/bin/python
Modified into
#!/usr/bin/python2.6.6
The yum command is now executed without the previous error message. We perform 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 1 line
/usr/local/lib
Save exit, and then
/sbin/ldconfig
/sbin/ldconfig -v
Step 2: install pip
Download the latest version of pip and install it
wget https://bootstrap.pypa.io/get-pip.py
python get-pip.py
Find the location of pip
whereis pip
Find the path to pip2.7 and create a soft link for it as the default boot version of the system
./configure --enable-shared --enable-loadable-sqlite-extensions --with-zlib
0
Now that the pip is installed, you can use it to install all the packages you need :)
Step 3: install scrapy
directly
pip install scrapy
Is ok
conclusion
That's all you need to know to upgrade CentOS 6.X 2.6 to Python2.7. I hope this article will help you in your study or work.