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:
- What packages do I need to install and in what order?
- Which packages should be installed while virtualenv is activated?
- How do I know whether to use
pip
,easy_install
, orapt-get install
? - If I run any of the commands above while the virtualenv is activated, are they only installed in the virtualenv?
- I seem to run into problems when I try to issue the above commands with
sudo
. I’ve avoided this issue by logging in asroot
. Is this to be expected?
Advertisement
Answer
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 needslibmysqlclient
(libmysqlclient18 - MySQL database client library
) too.after installing libmysqlclient and python-mysql using aptitude you can activate your virutualenv and install python-mysql package
pip install MySQL-python
. This will makeMySQLdb
avaialable within your virtualenvMysql 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.
if you
pip install
something while your virtualenv is active it will install it only into your virtual env.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>