[Django]-Problems with Django+mySQL+virtualenv

2đź‘Ť

for windows 7 32 bit installation of python 2.7 ..
activate the virtual environment and then at the environment prompt type

easy_install mysql-python

using pip did not work for me

👤bir singh

1đź‘Ť

VIrtualenv hasn’t inherited your global Python libraries, it doesn’t by default anymore.

You can recreate the virtualenv with the site packages, or you can install the mysql python module, which is built in C, and therefore less simple than most pip installs.

To install mysqldb under virtualenv, you need to be able to compile the mysql module, which means you need all the general compliation tools, the python header libraries and the mysql client ones (Under ubuntu/debian these are packages build-essential, python-dev & libmysqlclient16-dev ), at this point pip install MySQL-python should work, and from there you should be able to use mysql within django.

Doing this under windows, however, is complicated. One thing you can also do is add a file to the site-packages directory inside your virtual environment (lib/python2.7/site-packages) called something like mysql.pth (anything.pth will do) which contains a single line with the full path to the location of the mysql python libraries. This will add that directory to the searched path, and should also mean django can find the libraries.

👤Aquarion

1đź‘Ť

Extending previous answer, to inherit from system’s site-packages with a recent version of virtualenv, use

virtualenv --system-site-packages test
👤saaj

1đź‘Ť

If you have installed mysql-python on C:/python27 or globally, then just copy paste the following files from “C:/python/lib/site-packages” to your virtual environment “/lib/site-packages”

  • MySQL_python-1.2.4-py2.7.egg-info(folder)
  • MySQLdb(folder)
  • _mysql_exceptions.py/.pyc/.pyo
  • _mysql.pyd

**Don’t need to copy mysql files from “C:\Python27\Lib\site-packages\django\db\backends” or “C:\Python27\Lib\site-packages\django\contrib\gis\db\backends”. It worked like a charm

👤ruddra

0đź‘Ť

Looks like MySQLdb is not installed or at least not in the right place.

I used itsadok’s answer on Integrating MySQL with Python in Windows for my windows installation. You just download the installer and install it. I don’t know how it goes with virtualenv.

0đź‘Ť

👤user

Leave a comment