如何在Python 2.6的Linux系统上通过pip/virtualenv为Python 2.5安装MySQL-python?
我正在为一个Django项目设置虚拟环境,这个项目需要用到MySQL-python。我想要复制生产环境的设置,而生产环境使用的是Python 2.5。我的Ubuntu桌面上已经安装了Python 2.5。我可以通过命令virtualenv --python=/usr/bin/python2.5 ...
来安装Python 2.5的虚拟环境。不过,当我尝试用pip install MySQL-python
来安装时,出现了以下输出:
$ pip install MySQL-python
Downloading/unpacking MySQL-python
Running setup.py egg_info for package MySQL-python
warning: no files found matching 'MANIFEST'
warning: no files found matching 'ChangeLog'
warning: no files found matching 'GPL'
Installing collected packages: MySQL-python
Running setup.py install for MySQL-python
building '_mysql' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,3,'final',0) -D__version__=1.2.3 -I/usr/include/mysql -I/usr/include/python2.5 -c _mysql.c -o build/temp.linux-i686-2.5/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -DUNIV_LINUX -DUNIV_LINUX
In file included from _mysql.c:29:
pymemcompat.h:10: fatal error: Python.h: No such file or directory
compilation terminated.
error: command 'gcc' failed with exit status 1
我已经安装了python-dev
这个Ubuntu的deb包,但那是针对Python 2.6的。
还有什么其他方法可以安装MySQL-python
呢?
3 个回答
1
与其使用 pip 或 easy_install,你可以用 apt-get 来安装:
sudo apt-get install python-mysqldb
根据亚当的回复,我在 Ubuntu 12.04 和 Python 2.5 上并不需要从源代码安装。
4
其实,我找到了解决办法。我启用了一个叫做 Dead Snakes - 旧版Python库 的资源库,然后我就可以用 aptitude install python2.5-dev
来安装Python 2.5的开发工具,接着 pip install MySQL-python
就顺利安装成功了。
5
我在一台Ubuntu电脑上也遇到了同样的问题。在通过pip
安装MySQL-python之前,我需要先用以下命令从源代码编译这个模块和它的依赖项:
sudo apt-get build-dep python-mysqldb
可以看看这篇文章 - http://theviceprogrammer.com/?p=238