virtualenv pip install mysql-python 失败

Posted

技术标签:

【中文标题】virtualenv pip install mysql-python 失败【英文标题】:virtualenv pip install mysql-python fails 【发布时间】:2014-02-23 03:52:34 【问题描述】:

案例是我想使用 virtualenv 自动化我的部署过程。我在 git 存储库中有一个 python 项目。我使用詹金斯来自动化一切。在 jenkins 构建中,我执行以下操作:

连接到远程测试服务器 创建一个空的 virtualenv 下载我的项目(git clone) 安装依赖项 - 到 virtualenv 中

最后一步失败。我那里有 python 2.6.6。我运行 . bin/activate 进入 virtualenv 并运行 pip install mysql-python 来安装我的依赖项。以下是我得到的控制台输出:

Downloading/unpacking mysql-python
  Running setup.py (path:/var/www/_dev/ola_internal/build/mysql-python/setup.py) egg_info for package mysql-python
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,5,'final',1) -D__version__=1.2.5 -I/usr/include/mysql -I/usr/include/python2.6 -c _mysql.c -o build/temp.linux-x86_64-2.6/_mysql.o -g -fPIC -g -static-libgcc
 -fno-omit-frame-pointer -DPERCONA_INNODB_VERSION=rel31.1 -fPIC -g -static-libgcc -fno-omit-frame-pointer -fno-strict-aliasing -DMY_PTHREAD_FASTMUTEX=1
    _mysql.c:29:20: error: Python.h: No such file or directory
    _mysql.c:40:26: error: structmember.h: No such file or directory
    _mysql.c:74: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
    _mysql.c:75: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
    _mysql.c:76: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token
    _mysql.c:77: error: expected '=', ',', ';', 'asm' or '__attribute__' before '*' token

这里还有很多 C 错误我会省略。

[...]

结局是这样的:

_mysql.c: In function 'DL_EXPORT':

_mysql.c:3058: error: expected declaration specifiers before 'init_mysql'

_mysql.c:3166: error: expected '' at end of input

error: command 'gcc' failed with exit status 1

----------------------------------------
Cleaning up...
Command /var/www/_dev/ola_internal/bin/python -c "import setuptools, tokenize;__file__='/var/www/_dev/ola_internal/build/mysql-python/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-z0QiG8-record/install-record.txt --single-version-externally-managed --compile --install-headers /var/www/_dev/ola_internal/include/site/python2.6 failed with error code 1 in /var/www/_dev/ola_internal/build/mysql-python
Storing debug log for failure in /var/lib/jenkins/.pip/pip.log

这里发生了什么?这很奇怪,因为服务器上全局安装了 MySQLdb:

jenkins@olamd:/var/www/_dev/ola_internal$ python
Python 2.6.6 (r266:84292, Dec 26 2010, 22:31:48) 
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> MySQLdb.__version__
'1.2.2'

【问题讨论】:

【参考方案1】:

感谢this blog,原来我没有安装python-dev debian 包:

sudo apt-get install python-dev

【讨论】:

以上是关于virtualenv pip install mysql-python 失败的主要内容,如果未能解决你的问题,请参考以下文章

第16月第27天 pip install virtualenv

virtualenv pip install mysql-python 失败

pip install virtualenv 和 virtualenvwrapper 时出现不支持的语言环境设置错误

Python virtualenv pip install MySQL-Python 导致“RuntimeError:超出最大递归深度”

pip install scipy on virtualenv 错误 RHEL6.5

配置virtualenv