Python 2.7 MySQLdb errImportError:无法导入名称escape_sequence“ /Library/Python/2.7/site-packages/MySQLdb/converters.py”

时间:2019-05-16 15:16:13

标签: mysql python-2.7 pip

我已经在一个Python 2.7项目中导入了MySQLdb,并创建了一个初始化函数来从数据库中获取数据,以验证传递给另一个函数的数据。下面的代码是我调用 init 时所破坏的:

def __init__(self, username, password):
        print 'Initializing...'
        self.db_conn = MySQLdb.connect(host="host", user=username, passwd=password, db = "db")
        self.c = self.db_conn.cursor(MySQLdb.cursors.DictCursor)
        self.make_map = self.getJsonMap('make')
        self.model_map = self.getJsonMap('model')
        self.color_map = self.getJsonMap('color')
        self.getDBMakes()
        self.getDBModels()
        self.getDBColors()

我收到以下错误:

Traceback (most recent call last):
  File "clean.py", line 114, in <module>
    vc = ViolationCleaner('<user>', '<credential>')
  File "/Users/taddeskorris/PP/Code/migration/import_violations/ViolationCleaner.py", line 53, in __init__
    self.db_conn = MySQLdb.connect(host="host", user=username, passwd=password, db = "db")
  File "/Library/Python/2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/MySQLdb/connections.py", line 117, in __init__
    from MySQLdb.converters import conversions, _bytes_or_str
  File "/Library/Python/2.7/site-packages/MySQLdb/converters.py", line 35, in <module>
    from _mysql import string_literal, escape_sequence, escape_dict, escape, NULL

遵循堆栈跟踪信息将导致源自包装的错误。我最近下载了MySQL社区服务器的另一个版本,并尝试对其进行调试。 MySQL版本为mysql Ver 8.0.16 for macos10.14 on x86_64 (MySQL Community Server - GPL)

我对MySQL软件包的PIP依赖关系是:

mysql                                  0.0.2      
MySQL-python                           1.2.5      
mysqlclient                            1.4.2.post1

无论我做什么,当我尝试运行需要MySQL连接的Python脚本时,都会遇到相同的错误。

0 个答案:

没有答案