Press "Enter" to skip to content

centos6.x升级至python2.7并安装mysql-python

1.从官网下载2.7版本

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

2.安装

# tar -jxvf Python-2.7.1.tar.bz2
# cd Python-2.7.1
# ./configure   (如不指定 –prefix,默认安装在/usr/local/lib/python2.7)
# make && make install

3.升级默认版本

# mv python /usr/bin/python24
# ln -s /usr/local/bin/python2.7 /usr/bin/python
4.安装mysql-python

(安装方法不了解可以参看包内的README)

# 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
//=============
说明需要安装setuptools
5.安装 setuptools
先下载源代码包:

wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz#md5=7df2a529a074f613b509fb44feefe74e

解压后

python setup.py build

python setup.py install

 

6.在解决该问题的过程中,我发现了python安装方法中最简易的一种“easy_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/binInstalled /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 

7.安装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
cmd_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 

以上错误提示没有安装mysql环境,需要安装mysql,此处省略N个字,安装好mysql以后,再度安装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-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

8.此时应该算是将mysql-python安装上了,检验一下: 

# 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

>>>

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据