ImportError:没有名为authentication的模块

时间:2014-09-24 16:44:51

标签: python mysql mysql-connector-python

我已经安装了MySQL Connector / Python模块。它显示在目录/usr/lib/python2.7/site-packages/mysql/connector/中。我还将此目录添加到$ PATH。

当我执行以下Python程序时,我收到以下错误。

import mysql.connector
config = {
    "database": "XXXX",
    "host": "XXXX",
    'user': 'XXXX',
    "password": "XXXX",
    "table": "XXXX",
    "charset": "utf8"
}

try:
    cnx = mysql.connector.connect(**config)

except mysql.connector.Error as err:
  if err.errno == errorcode.ER_ACCESS_DENIED_ERROR:
    print("Something is wrong with your user name or password")
  elif err.errno == errorcode.ER_BAD_DB_ERROR:
    print("Database does not exists")
  else:
    print(err)
else:
  cnx.close()

错误:

Traceback (most recent call last):
  File "config.py", line 1, in <module>
    import mysql.connector
  File "/usr/lib/python2.7/site-packages/mysql/connector/__init__.py", line 28, in <module>
  File "/usr/lib/python2.7/site-packages/mysql/connector/connection.py", line 39, in <module>
  File "/usr/lib/python2.7/site-packages/mysql/connector/protocol.py", line 34, in <module>
ImportError: No module named authentication

在目录/usr/lib/python2.7/site-packages/mysql/connector/中,有一个authentication.py和authentication.pyc。

我不明白这个问题......

1 个答案:

答案 0 :(得分:1)

问题是组成MySQL软件包的目录和文件是在PYTHONPATH中,但是没有读取权限(除root之外)。答案是chmod a+x目录和chmod a+r *.py该目录和子目录中的文件。