MySQL connector/python ImportError: No module named 'mysql'
I'm very new to Ubuntu/Linux and Python so it's entirely possible I'm missing something obvious here. I'm running Ubuntu 16.04 LTS, server version.
I've just installed the official MySQL connector/python (2.1.7, python3 version) using dpkg -i [package-name].deb (obviously I replaced [package-name] with the actual name). It's listed as being compatible with Python 3.5, which is the version I have. When I try to verify the installation through the Python interpreter using import mysql.connector, I just get the following error:
>>> import mysql.connector
Traceback (most recent call last): File "<stdin>", line 1, in <module>
ImportError: No module named 'mysql'On one similar question, I've seen it suggested that the connector may not have installed properly if python is not in the path. I didn't seem to get any issues during the installation; the file python3 is in /usr/bin which is definitely in the path, but seems to be a link to the file python3.5 in the same location. Running the command which python3 gives the output usr/bin/python3 but running which python gives no output.
The package apparently also contained a C library, which seems to have installed in usr/lib/python3/dist-packages. Nothing else in that directory is called anything related to MySQL.
What should I be looking for to know whether it's an issue with the connector installation or with Python itself? And how do I fix this?
1 Answer
The solution is to install corresponding Python 3 module:
sudo apt-get install python3-mysql.connectorIt fixes import mysql.connector error:
$ python3
Python 3.5.2 (default, Nov 23 2017, 16:37:01)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
>>> And similar for Python 2:
sudo apt-get install python-mysql.connector
$ python2
Python 2.7.12 (default, Dec 4 2017, 14:50:18)
[GCC 5.4.0 20160609] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
>>> 3 More in general
"Zoraya ter Beek, age 29, just died by assisted suicide in the Netherlands. She was physically healthy, but psychologically depressed. It's an abomination that an entire society would actively facilitate, even encourage, someone ending their own life because they had no hope. Th…"