Upgrade centos5.x to python2.7 and MySQL-Python

Source: Internet
Author: User

The Python version of centos5.3 is really tearful. When is it 2.4. Self-help clothes and food.

1. download version 2.7 from the official website

 

# Wget http://www.python.org/ftp/python/2.7.1/Python-2.7.1.tar.bz2

 

2. Installation

 

# Tar-jxvf Python-2.7.1.tar.bz2
# Cd Python-2.7.1
#./Configure (if -- prefix is not specified, it is installed in/usr/local/lib/python2.7 by default)
# Make & make install

 

3. Upgrade the default version

 

# Mv Python/usr/bin/python24
# Ln-S/usr/local/bin/python2.7/usr/bin/Python

 

4. Install mysql-Python

(For details about the installation method, see readme in the package)

# Python setup. py build
Traceback (most recent call last ):
File "setup. py", line 5, in <module>
From setuptools import setup, extension
Importerror: No module named setuptools

What is the situation? It seems that setuptools does not exist.

5. Go to the official website to download setuptools

Official Website

# Bash setuptools-0.6c11-py2.7.egg

Traceback (most recent call last ):

File "<string>", line 1, in <module>

Zipimport. zipimporterror: Can't decompress data; zlib not available

What is the situation? Zlib missing? (For the software environment required for installing python, see readme)

This step took me a long time to solve it, and the process was really unpleasant. From the above error message, it seems that zlib does not exist. The first thing that comes to mind is to use Yum to install zlib *.

# Rpm-Qa | grep zlib
Zlib-1.2.3-3
Zlib-devel-1.2.3-3

After re-compiling python, the system still prompts this error "zipimport. zipimporterror: Can't decompress data; zlib not available", which is a bit crazy at the end. When I was about to worry about browsing the official site of zlib, its latest version is zlib-1.2.5. I decided to use the tar package to install the latest version.

The installation process is very simple, but it is still three steps:

# Cd zlib-1.2.5
#./Configure

# Make & make install


In the process of solving this problem, I found the simplest "easy_install" in the python installation method, which will be used to install mysql-Python

# Wget http://peak.telecommunity.com/dist/ez_setup.py
# Python ez_setup.py
Downloading http://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg
Processing setuptools-0.6c11-py2.7.egg
Copying setuptools-0.6c11-py2.7.egg to/usr/local/lib/python2.7/Site-packages
Adding setuptools 0.6c11 to easy-install.pth File
Installing easy_install script to/usr/local/bin
Installing easy_install-2.7 script to/usr/local/bin.

Installed/usr/local/lib/python2.7/Site-packages/setuptools-0.6c11-py2.7.egg
Processing dependencies for setuptools = 0.6c11

Finished processing dependencies for setuptools = 0.6c11


In the previous step, it installed the setuptools-0.6c11-py2.7.egg on its own so that you can use easy_install.

4. Install mysql-Python

# Easy_install mysql-Python
Searching for MySQL-Python
Reading http://pypi.python.org/simple/MySQL-python/
Reading http://sourceforge.net/projects/mysql-python/
Reading http://sourceforge.net/projects/mysql-python
Best Match: mysql-Python 1.2.3
Downloading http://download.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.3.tar.gz
Processing MySQL-python-1.2.3.tar.gz
Running MySQL-python-1.2.3/setup. py-Q bdist_egg -- dist-DIR/tmp/easy_install-0IG0OI/MySQL-python-1.2.3/egg-dist-tmp-pBvQ9I
SH: mysql_config: Command not found
Traceback (most recent call last ):
File "/usr/local/bin/easy_install", line 8, in <module>
Load_entry_point ('setuptools = 0.6c11 ', 'console _ scripts', 'easy _ install ')()
File "/usr/local/lib/python2.7/Site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 1712, in Main
File "/usr/local/lib/python2.7/Site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 1700, in with_ei_usage
File "/usr/local/lib/python2.7/Site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 1716, in <Lambda>
File "/usr/local/lib/python2.7/distutils/CORE. py", line 152, in setup
Dist. run_commands ()
File "/usr/local/lib/python2.7/distutils/Dist. py", line 953, in run_commands
Self. run_command (CMD)
File "/usr/local/lib/python2.7/distutils/Dist. py", line 972, in run_command
Performance_obj.run ()
File "/usr/local/lib/python2.7/Site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 211, in run
File "/usr/local/lib/python2.7/Site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 446, in easy_install
File "/usr/local/lib/python2.7/Site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 476, in install_item
File "/usr/local/lib/python2.7/Site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 655, in install_eggs
File "/usr/local/lib/python2.7/Site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 930, in build_and_install
File "/usr/local/lib/python2.7/Site-packages/setuptools-0.6c11-py2.7.egg/setuptools/command/easy_install.py", line 919, in run_setup
File "/usr/local/lib/python2.7/Site-packages/setuptools-0.6c11-py2.7.egg/setuptools/sandbox. py", line 62, in run_setup
File "/usr/local/lib/python2.7/Site-packages/setuptools-0.6c11-py2.7.egg/setuptools/sandbox. py", line 105, in run
File "/usr/local/lib/python2.7/Site-packages/setuptools-0.6c11-py2.7.egg/setuptools/sandbox. py", line 64, in <Lambda>
File "setup. py", line 15, in <module>
File "/tmp/easy_install-0IG0OI/MySQL-python-1.2.3/setup_posix.py", line 43, in get_config
File "/tmp/easy_install-0IG0OI/MySQL-python-1.2.3/setup_posix.py", line 24, in mysql_config

Environmenterror: mysql_config not found


The preceding error message indicates that the MySQL environment is not installed. MySQL needs to be installed. n characters are omitted here. After MySQL is installed, install mysql-Python again.

# Easy_install mysql-Python

Searching for MySQL-Python
Reading http://pypi.python.org/simple/MySQL-python/
Reading http://sourceforge.net/projects/mysql-python/
Reading http://sourceforge.net/projects/mysql-python
Best Match: mysql-Python 1.2.3
Downloading http://download.sourceforge.net/sourceforge/mysql-python/MySQL-python-1.2.3.tar.gz
Processing MySQL-python-1.2.3.tar.gz
Running MySQL-python-1.2.3/setup. py-Q bdist_egg -- dist-DIR/tmp/easy_install-w7wAW2/MySQL-python-1.2.3/egg-dist-tmp-CCgmn2
Warning: no files found matching 'manifest'
Warning: no files found matching 'changelog'
Warning: no files found matching 'gpl'
......
Zip_safe flag not set; analyzing archive contents...
Adding mysql-Python 1.2.3 to easy-install.pth File

Installed/usr/local/lib/python2.7/Site-packages/MySQL_python-1.2.3-py2.7-linux-x86_64.egg
Processing dependencies for MySQL-Python

Finished processing dependencies for MySQL-Python

 

5. You have installed mysql-Python. Check the following:

# Python

Python 2.7.1 (r271: 86832, Apr 27 2011, 15:54:05)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "Copyright", "Credits" or "License" for more information.
>>> Import mysqldb
Traceback (most recent call last): file "build/bdist. linux-x86_64/egg/_ mysql. py", line 6, in _ Bootstrap __

File "<stdin>", line 1, in <module> file "build/bdist. linux-x86_64/egg/mysqldb/_ init __. PY ", line 19, in <module> file" build/bdist. linux-x86_64/egg/_ MySQL. PY ", line 7, in <module> importerror: libmysqlclient. so.16: cannot open shared object file: no such file or directory

 

It really hurts people. 99 steps have passed. Edit the lD. So. conf file and add the directory of libmysqlclient. so.16:

# Vi/etc/lD. So. conf

/Usr/local/innosql-5.5.8-linux-x86_64/lib/

# Ldconfig-V

 

Test again, Ko

# Python
Python 2.7.1 (r271: 86832, Apr 27 2011, 15:54:05)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "Copyright", "Credits" or "License" for more information.
>>> Import mysqldb

>>>

 

Although the above installation process has no technical content, it is very annoying. I really hope that the uncles of the RedHat series will slightly upgrade their own Python version!

 

Refer:

Http://www.question-defense.com/2009/03/16/install-easy_install-via-yum-on-linux-centos-server

Http://villaroad.com/2010/10/rolling-python-2-6-2-on-centos-5-3/

Http://toey.tc20.net/2010/08/04/install-python-2-7-gevent-on-centos-5-x86_64/

Http://www.sou5.cn/archives/tag/easy_install

Http://my.oschina.net/captaintheron/blog/3668

Http://blog.csdn.net/wxkingstar/archive/2009/09/08/4530651.aspx

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.