I installed mysql connector with pip, so now I have:
$ pip install mysql-connector
Requirement already satisfied: mysql-connector in /usr/local/lib/python2.7/dist-packages
$ pip install mysql-connector-python-rf
Requirement already satisfied: mysql-connector-python-rf in /usr/local/lib/python2.7/dist-packages
from mysql.connector import errorcode
$ python mysqlTest.py
Traceback (most recent call last):
File "mysqlTest.py", line 1, in <module>
File "/home/user/mysql.py", line 1, in <module>
ImportError: No module named connector
$ python --version
Sounds like there is something wrong with your module's path. Maybe you're importing the wrong module. I would try to
print mysql.__file__ to make sure you're importing the right module.
In addition, using
virtualenv is almost guaranteed to solve this kind of problems which usually stem from collisions between different Python interpreters and / or modules with similar names.
pip install virtualenvto install virtualenv.
virtualenv venvto create a Python virtual environment in your current directory.
source venv/bin/activateto activate the virtual environment.
pipas you normally would and try running the script again.
More info on virtualenv can be found in the official docs.