我已经通过以下步骤在Mac上安装了MySQL-python:
pip uninstall MySQL-python
brew install mysql
pip install MySQL-python
然后测试一下:
python -c "import MySQLdb"
当我测试它时,它在我的mac终端上给了我以下错误:
ImportError:这是MySQLdb版本(1,2,4,'beta',4),但_mysql是版本(1,2,5,'final',1)
请帮我解决这个问题。
答案 0 :(得分:2)
在路径下:
/Library/Python/2.7/site-packages
在我的Mac上,我可以看到 MySQL_python-1.2.5-py2.7.egg-info 和 MySQLdb 只需删除文件MySQL_python-1.2.5-py2.7.egg-info /就可以解决问题:
sudo rm -rf MySQL_python-1.2.5-py2.7.egg-info /
答案 1 :(得分:2)
我在运行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 <farcepest@gmail.com>"
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 :(得分: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