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?
Best Answer
The solution is to install corresponding Python 3 module:
It fixes
import mysql.connector
error:And similar for Python 2: