导入错误:这是MySQLdb的版本(1,2,4, '测试',4),但_mysql是版本(1,2,5, '最终',1)

问题描述 投票:3回答:4

我已经安装了MySQL的Python在Mac上使用以下步骤:

pip uninstall MySQL-python
brew install mysql
pip install MySQL-python

然后对其进行测试:

python -c "import MySQLdb"

当我测试它,它给了我下面我的Mac终端上的错误:

导入错误:这是MySQLdb的版本(1,2,4, '测试',4),但_mysql是版本(1,2,5, '最终',1)

请帮我解决这个问题。

python mysql macos python-2.7 mysql-python
4个回答
3
投票

我有当我运行一个Python程序airflow此错误:

问题

$airflow
Traceback (most recent call last):
  File "/home/idx/.virtualenvs/airflow/bin/airflow", line 16, in <module>
    from airflow import configuration
  File "/home/idx/.virtualenvs/airflow/lib/python2.7/site-packages/airflow/__init__.py", line 31, in <module>
    from airflow import settings
  File "/home/idx/.virtualenvs/airflow/lib/python2.7/site-packages/airflow/settings.py", line 150, in <module>
configure_orm()
  File "/home/idx/.virtualenvs/airflow/lib/python2.7/site-packages/airflow/settings.py", line 136, in configure_orm
engine = create_engine(SQL_ALCHEMY_CONN, **engine_args)
  File "/home/idx/.virtualenvs/airflow/lib/python2.7/site-packages/sqlalchemy/engine/__init__.py", line 419, in create_engine
return strategy.create(*args, **kwargs)
  File "/home/idx/.virtualenvs/airflow/lib/python2.7/site-packages/sqlalchemy/engine/strategies.py", line 80, in create
    dbapi = dialect_cls.dbapi(**dbapi_args)
  File "/home/idx/.virtualenvs/airflow/lib/python2.7/site- 
    packages/sqlalchemy/dialects/mysql/mysqldb.py", line 102, in dbapi
    return __import__('MySQLdb')
  File "/home/idx/.virtualenvs/airflow/lib/python2.7/site-packages/MySQLdb/__init__.py", line 23, in <module>
(version_info, _mysql.version_info))
ImportError: this is MySQLdb version (1, 2, 5, 'final', 1), but _mysql is version (1, 4, 1, 'final', 0)

背景

我用的是MySQLdb的是:/home/will/.local/lib/python2.7/site-packages/MySQLdb/。在该目录中的cat release.py显示1.2.5 final 1

__author__ = "Andy Dustman <[email protected]>"
version_info = (1,2,5,'final',1)
__version__ = "1.2.5"

固定

为了使版本匹配,我跑了下面和固定对我来说:

# for some reason, even though I had mysqlclient==1.4.1 from pip freeze, I had to uninstall it first, then reinstall
pip uninstall mysqlclient
pip install mysqlclient==1.4.1

2
投票

在路径:

/library/Python/2.7/site-packages

我的Mac上,我可以看到MySQL_python-1.2.5-py2.7.egg-信息和MySQLdb的只是删除文件MySQL_python-1.2.5-py2.7.egg-INFO /可以解决这个问题:

须藤室射频MySQL_python-1.2.5-py2.7.egg-INFO /


1
投票

这是一个兼容性问题。我所做的就是把我的MySQL的蟒蛇到1.2.4b4。

如果你已经MySQLdb的安装卸载

PIP卸载的MySQL蟒蛇

然后用相同的版本安装:

PIP安装mysql-python的== 1.2.4b4

这是所述β-因此在B

这对我的作品。我测试通过进入蟒蟒与互动

然后导入MySQLdb的和它的工作。希望这可以帮助


0
投票

您可以重新安装你MySQLdb-python并安装此版本:MySQLdb-python-1.2.5

    pip uninstall MySQL_python
    pip install -Iv https://pypi.python.org/packages/source/M/MySQL-python/MySQL-python-1.2.5.zip#md5=654f75b302db6ed8dc5a898c625e030c
© www.soinside.com 2019 - 2024. All rights reserved.