【问题标题】:How can I install MySQL-python via pip/virtualenv for Python 2.5 on a Linux system with Python 2.6?如何在具有 Python 2.6 的 Linux 系统上通过 pip/virtualenv 为 Python 2.5 安装 MySQL-python?
【发布时间】:2011-07-26 01:27:10
【问题描述】:

我正在尝试为 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

【问题讨论】:

    标签: python virtualenv pip mysql-python


    【解决方案1】:

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

    sudo apt-get build-dep python-mysqldb
    

    请参阅这篇文章 - http://theviceprogrammer.com/?p=238

    【讨论】:

      【解决方案2】:

      其实找到了解决办法,我启用了Dead Snakes - old python version存储库,然后我可以aptitude install python2.5-dev,然后pip install MySQL-python工作了

      【讨论】:

        【解决方案3】:

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

        sudo apt-get install python-mysqldb
        

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

        【讨论】:

          猜你喜欢
          • 2014-08-09
          • 1970-01-01
          • 2015-08-12
          • 2017-03-23
          • 1970-01-01
          • 1970-01-01
          • 2016-01-24
          • 1970-01-01
          相关资源
          最近更新 更多