Question

The case is I want to automate my deployment process using virtualenv. I do have a python project in a git repository. I use jenkins to automate everything. Inside a jenkins build, I do the following:

  • connect to a remote test-server
  • create an empty virtualenv
  • download my project (git clone)
  • install dependencies - into the virtualenv

The last step fails. I've got python 2.6.6 there. I run . bin/activate to enter virtualenv and run pip install mysql-python to install my dependency. The following is the console output I get:

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

There is a lot more C errors here I'll omit.

[...]

and the end is like that:

_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

What's going on here? This is very strange, since there is MySQLdb installed globally on the server:

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'
Was it helpful?

Solution

Thanks to this blog, it occurs that I didn't have python-dev debian package installed:

sudo apt-get install python-dev
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top