mySQL within Python 2.7.9
Question: Arrghh... I am trying to use mySQL with Python. I have installed all the
libraries for using mySQL, but keep getting the: "ImportError: No module named
mysql.connector" for "import mysql.connector", "mysql", etc..

Here is my config:

I have a RHEL server:

> Red Hat Enterprise Linux Server release 6.7 (Santiago)

with Python 2.7.9

> Python 2.7.9 (default, Dec 16 2014, 10:42:10) [GCC 4.4.7 20120313 (Red Hat
> 4.4.7-11)] on linux2

with mySQL 5.1

> mysql Ver 14.14 Distrib 5.1.73, for redhat-linux-gnu (x86_64) using readline
> 5.1

* * *

I have all the appropriate libraries/modules installed, I think!

yum install MySQL-python

> Package MySQL-python-1.2.3-0.3.c1.1.el6.x86_64 already installed and latest
> version

yum install mysql-connector-python.noarch

> Installed: mysql-connector-python.noarch 0:1.1.6-1.el6  
>  yum install MySQL-python.x86_64 Package MySQL-
> python-1.2.3-0.3.c1.1.el6.x86_64 already installed and latest version

yum install mysql-connector-python.noarch

> Package mysql-connector-python-1.1.6-1.el6.noarch already installed and
> latest version

* * *

What am I doing wrong? HELP!?


Answer: You should use `virtualenv` in order to isolate the environment. That way your
project libs won't clash with other projects libs. Also, you probably should
install the `Mysql` driver/connector from `pip`.

`Virtualenv` is a CLI tool for managing your environment. It is really easy to
use and helps a lot. What it does is to create all the folders Python needs on
a custom location (usually your specific project folder) and it also sets all
the shell variables so that Python can find the folders. Your system (/usr and
so on) folders are not removed from the shell; rather, they just get a low
priority. That is done by correctly setting your `PATH` variable, and
`virtualenv` does that when you load a determined environment.

It is common practice to use an environment for each project you work on. That
way, Python and `pip` won't install libs on the global folders. Instead, `pip`
installs the libs on the current environment you are using. That avoids
version conflicts and even Python version conflicts.

