Python - MySQL Connector error in Mac OSX 10.10
Asked Answered
B

1

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.

Blandina answered 24/4, 2015 at 14:37 Comment(0)
M
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
Misleading answered 24/4, 2015 at 15:5 Comment(5)
yes. it is not a part of Mac OSX default install. I Installed it from XAMPP.Blandina
>>> import sys >>> sys.path() Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: 'list' object is not callable I tried to get the python path. But this occurred .Blandina
yep - typo - it's an attribute and not a method.Misleading
Another option is to download a binary distribution from: dev.mysql.com/downloads/connector/python They provide an image disk with an installer for OS X.Hasidism
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).Epifocal

© 2022 - 2024 — McMap. All rights reserved.