Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Have MySQLdb installed, works outside of virtualenv but inside it doesn't exist. How to resolve?

I'm using the most recent versions of all software (Django, Python, virtualenv, MySQLdb) and I can't get this to work. When I run "import MySQLdb" in the python prompt from outside of the virtualenv, it works, inside it says "ImportError: No module named MySQLdb".

I'm trying to learn Python and Linux web development. I know that it's easiest to use SQLLite, but I want to learn how to develop larger-scale applications comparable to what I can do in .NET. I've read every blog post on Google and every post here on StackOverflow and they all suggest that I run "sudo pip install mysql-python" but it just says "Requirement already satisfied: mysql-python in /usr/lib/pymodules/python2.7"

Any help would be appreciated! I'm stuck over here and don't want to throw in the towel and just go back to doing this on Microsoft technologies because I can't even get a basic dev environment up and running.

like image 280
dudemonkey Avatar asked Nov 08 '12 11:11

dudemonkey


2 Answers

If you have created the virtualenv with the --no-site-packages switch (the default), then system-wide installed additions such as MySQLdb are not included in the virtual environment packages.

You need to install MySQLdb with the pip command installed with the virtualenv. Either activate the virtualenv with the bin/activate script, or use bin/pip from within the virtualenv to install the MySQLdb library locally as well.

Alternatively, create a new virtualenv with system site-packages included by using the --system-site-package switch.

like image 144
Martijn Pieters Avatar answered Nov 05 '22 06:11

Martijn Pieters


  1. source $ENV_PATH/bin/activate
  2. pip uninstall MySQL-python
  3. pip install MySQL-python

this worked for me.

like image 41
fwindpeak Avatar answered Nov 05 '22 06:11

fwindpeak