Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Installing MySQL-python for Django

I've just learned how to use virtualenv and I installed Django 1.4.5. I'm assuming that the virtualenv created a clean slate for me to work on so with the Django 1.4.5 installed, I copied all my previous files into the virtualenv environment.

I tried to run the server but I get an error saying "no module named MySQLdb". I think this means that I forgot to install MySQL-python. I tried to install it via

    pip install MySQL-python

But I get this error

    Downloading/unpacking MySQL-python
    Running setup.py egg_info for package MySQL-python
    The required version of distribute (>=0.6.28) is not available,
    and can't be installed while this script is running. Please
    install a more recent version first, using
    'easy_install -U distribute'.

    (Currently using distribute 0.6.24     (/home/bradford/Development/Django/django_1.4.5/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg))
    Complete output from command python setup.py egg_info:
    The required version of distribute (>=0.6.28) is not available,

    and can't be installed while this script is running. Please

    install a more recent version first, using

    'easy_install -U distribute'.



    (Currently using distribute 0.6.24  (/home/bradford/Development/Django/django_1.4.5/lib/python2.7/site-packages/distribute-0.6.24-py2.7.egg))

    ----------------------------------------
    Command python setup.py egg_info failed with error code 2 in /home/bradford/Development/Django/django_1.4.5/build/MySQL-python

Not quite sure how to go about fixing this problem =/ any help much appreciated!

like image 723
Liondancer Avatar asked May 08 '13 10:05

Liondancer


People also ask

Can I use MySQL with Django?

Django supports MySQL 5.7 and higher.


2 Answers

I recently had exactly this issue (just not in relation to Django). In my case I am developing on Ubuntu 12.04 using the default pip and distribute versions, which are basically a little out of date for MySQL-python.

Because you are working in an isolated virtualenv, you can safely follow the suggested instruction without affecting your Python installation.

So you can...

workon your_virtualenv #activate your virtualenv, you do use virtualenvwrapper, right?
easy_install -U distribute #update distribute on your virtualenv
pip install MySQL-python #install your package

If for some reason upgrading distribute is not an option, you could try installing an older version of MySQL-python as follows (you'd have to check this version is compatible with your version of Django):

pip install MySQL-python==x.y.z #where x.y.z is the version you want
like image 125
lofidevops Avatar answered Oct 27 '22 15:10

lofidevops


MySQL driver for Python (mysql-python) needs libmysqlclient-dev. You can get it with:

sudo apt-get update
sudo apt-get install libmysqlclient-dev

If python-dev is not installed, you may have to install it too:

sudo apt-get install python-dev

Now you can install MySQL driver:

pip install mysql-python

Here is a more detailed documentation for MySQL in Django:

http://codex.themedelta.com/how-to-install-django-with-mysql-in-a-virtualenv-on-linux/

like image 27
Sibi M Avatar answered Oct 27 '22 15:10

Sibi M