Skip to main content
 首页 » 编程设计

python之如何在 Python 2.6 的 Linux 系统上通过 pip/virtualenv 为 Python 2.5 安装 MySQL-python

2025年05月04日18xing901022

我正在尝试为 Django 项目设置一个 virtualenv。它需要 MySQL-python。我正在尝试复制使用 Python 2.5 的生产环境。我的 Ubuntu 桌面有 Python 2.5。我可以使用 virtualenv --python=/usr/bin/python2.5 ... 安装 Python 2.5 virtualenv。然而,当我尝试 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?

请您参考如下方法:

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

sudo apt-get build-dep python-mysqldb 

请参阅本文 - http://theviceprogrammer.com/?p=238