1

我正在尝试为 Django 项目设置 virtualenv。它需要 MySQL-python。我正在尝试复制使用 Python 2.5 的生产环境。我的 Ubuntu 桌面有 Python 2.5。我可以使用virtualenv --python=/usr/bin/python2.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-devUbuntu deb 包,但这是针对 Python 2.6 的。

我还能如何MySQL-python安装?

4

3 回答 3

5

我在 Ubuntu 机器上遇到了同样的问题。在通过 安装 MySQL-python 之前pip,我需要使用以下命令从源代码编译模块和依赖项:

sudo apt-get build-dep python-mysqldb

看到这篇文章 - http://theviceprogrammer.com/?p=238

于 2011-09-08T23:38:50.670 回答
4

实际上,找到了一个解决方案,我启用了Dead Snakes - old python version repository,然后我可以aptitude install python2.5-dev,然后pip install MySQL-python工作

于 2011-03-30T12:23:06.570 回答
1

您可以使用 apt-get,而不是使用 pip 或 easy_install:

sudo apt-get install python-mysqldb

在带有 Python 2.5 的 Ubuntu 12.04 上,我不需要根据亚当的回复从源代码中获取

于 2013-04-28T11:36:12.270 回答