Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - MySQL Connector error in Mac OSX 10.10

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.

like image 454
Krishna Avatar asked Apr 24 '15 14:04

Krishna


1 Answers

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
like image 108
cgseller Avatar answered Nov 11 '22 16:11

cgseller