Amandasaurus
Amandasaurus

Reputation: 60759

How can I install MySQL-python via pip/virtualenv for Python 2.5 on a Linux system with Python 2.6?

I am trying to set up a virtualenv for a Django project. It needs MySQL-python. I'm trying to replicate the production environment, which uses Python 2.5. My Ubuntu desktop has Python 2.5. I can install the Python 2.5 virtualenv with virtualenv --python=/usr/bin/python2.5 .... However when I try to pip install MySQL-python, I get this output:

$ 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

I have installed the python-dev Ubuntu deb package, but that's for Python 2.6.

How else can I get MySQL-python installed?

Upvotes: 1

Views: 6372

Answers (3)

mozboz
mozboz

Reputation: 1109

Instead of using pip or easy_install, you can use apt-get:

sudo apt-get install python-mysqldb

Requiring from source as per adam's reply wasn't require for me, on Ubuntu 12.04 w/ Python 2.5

Upvotes: 1

adam
adam

Reputation: 6738

I had this same problem on an Ubuntu box. Prior to installing MySQL-python via pip, I needed to compile the module and dependencies from source using the following command:

sudo apt-get build-dep python-mysqldb

see this article - http://theviceprogrammer.com/?p=238

Upvotes: 5

Amandasaurus
Amandasaurus

Reputation: 60759

Actually, found a solution, I enabled the Dead Snakes - old python version repository, then I could aptitude install python2.5-dev, and then pip install MySQL-python worked

Upvotes: 4

Related Questions