Python - Mac OSX 10.10中的MySQL连接器错误

时间:2021-08-10 05:14:07
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

我用这段代码来检查我使用mysql提供的安装程序安装的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.

非常感谢帮助。

1 个解决方案

#1


10  

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

对于内置的python,我认为mysql包不是MacOSX默认安装(不适合我)的一部分。

You can solve this via pip

你可以通过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库路径来验证是否有一个mysql包。要获取python路径,请执行以下操作:

python
import sys
sys.path

#1


10  

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

对于内置的python,我认为mysql包不是MacOSX默认安装(不适合我)的一部分。

You can solve this via pip

你可以通过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库路径来验证是否有一个mysql包。要获取python路径,请执行以下操作:

python
import sys
sys.path