Skip to content
Advertisement

Sorting out Django and MySQL in virtualenv

I’m following this tutorial to get started with Django, but I’m very confused about how to integrate MySQL. Doing this in the context of virtualenv (which is new to me) seems to complicate things even further.

I’m running on Ubuntu and the MySQL server is on another host. Here are my specific questions:

  1. What packages do I need to install and in what order?
  2. Which packages should be installed while virtualenv is activated?
  3. How do I know whether to use pip, easy_install, or apt-get install?
  4. If I run any of the commands above while the virtualenv is activated, are they only installed in the virtualenv?
  5. I seem to run into problems when I try to issue the above commands with sudo. I’ve avoided this issue by logging in as root. Is this to be expected?

Advertisement

Answer

  1. You need to install the system library. This is global and does not happen inside a virtualenv. If you have aptitude it is as easy as sudo apt-get install python-mysqldb this alos needs libmysqlclient (libmysqlclient18 - MySQL database client library) too.

  2. after installing libmysqlclient and python-mysql using aptitude you can activate your virutualenv and install python-mysql package pip install MySQL-python. This will make MySQLdb avaialable within your virtualenv

  3. Mysql is a tricky package because it requires the mysql client libraries, which must be installed on your system. the vast majority of python packages will be available on pip or through github (which you can easily install through pip) and will not require extra system packages.

  4. if you pip install something while your virtualenv is active it will install it only into your virtual env.

  5. You will probably need to run sudo to install system wide packages using aptitude. Please don’t log in as root, you can grant your user sudo access

THe good news is mysql is pretty much as difficult as it gets. Almost all other python packages are as simples as activating your environment, and pip install <pacakge_name>

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement