I've installed MySQL-python on mac with following procedure :
pip uninstall MySQL-python
brew install mysql
pip install MySQL-python
Then test it :
python -c "import MySQLdb"
When I test it, it gave me following error on my mac terminal :
ImportError: this is MySQLdb version (1, 2, 4, 'beta', 4), but _mysql is version (1, 2, 5, 'final', 1)
Please help me with this issue.
I had this error when I was running a Python program airflow
:
Issue
$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)
Background
The MySQLdb that I was using was in: /home/will/.local/lib/python2.7/site-packages/MySQLdb/
. A cat release.py
in that directory showed the 1.2.5 final 1
.
__author__ = "Andy Dustman <[email protected]>"
version_info = (1,2,5,'final',1)
__version__ = "1.2.5"
Fix
To make the versions match, I ran the below and that fixed it for me:
# 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With