12
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.

BoJack Horseman
  • 4,406
  • 13
  • 38
  • 70
Krishna
  • 673
  • 3
  • 6
  • 21

1 Answers1

15

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
cgseller
  • 3,875
  • 2
  • 19
  • 21
  • yes. it is not a part of Mac OSX default install. I Installed it from XAMPP. – Krishna Apr 25 '15 at 06:02
  • >>> import sys >>> sys.path() Traceback (most recent call last): File "", line 1, in TypeError: 'list' object is not callable I tried to get the python path. But this occurred . – Krishna Apr 25 '15 at 06:04
  • yep - typo - it's an attribute and not a method. – cgseller Apr 25 '15 at 20:23
  • Another option is to download a binary distribution from: http://dev.mysql.com/downloads/connector/python/ They provide an image disk with an installer for OS X. – Hector Correa Nov 15 '16 at 21:09
  • The command `pip install mysql-connector-repackaged` worked, but only in `virualenv`. All other installations on El Capitan somehow failed to work (including the official connector). – marw Jan 06 '17 at 15:01