Python - MySQL Connector error in Mac OSX 10.10

Krishna picture Krishna · Apr 24, 2015 · Viewed 8.7k times · Source
import mysql.connector

config = {
    'user' : 'root',
    'passwd' : ' ',
    'host' : 'localhost',
    'raise_on_warnings' : True,
    'use_pure' : False,
    }
cnx = mysql.connector.connect(**config)

cnx.close()

I used this code to check my mysql package that I installed using the installer provided by the mysql

I ran the file in terminal and the result was,

Traceback (most recent call last):
 File "/Users/Krishna/Documents/check.py", line 1, in <module>
   import mysql.connector
ImportError: No module named 'mysql'

Help is highly appreciated.

Answer

cgseller picture cgseller · Apr 24, 2015

I don't think the mysql package is part of the MacOSX default install (it was not for me) for the built-in python.

You can solve this via pip

sudo pip install mysql-connector-repackaged

Verify by checking in the Python Library Path to see if you have a package for mysql there. To get your python path, do:

python
import sys
sys.path