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:
sudo. I’ve avoided this issue by logging in as
root. Is this to be expected?
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
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 make
MySQLdb avaialable within your virtualenv
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.
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>