ImportError: this is MySQLdb version (1, 2, 4, 'beta', 4), but _mysql is version (1, 2, 5, 'final', 1)

11.5k views Asked by At

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.

5

There are 5 answers

4
Chung-Yen Hung On

You can re-install your MySQLdb-python and install this version: 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
0
dynamo On

Do

 pip uninstall mysqlclient

then do

pip install mysqlclient==1.3.14 

as 1.4.1 version having some issues

0
Will On

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
0
vissac On

Under the path:

/Library/Python/2.7/site-packages

On my mac I can see MySQL_python-1.2.5-py2.7.egg-info and MySQLdb Just remove the file MySQL_python-1.2.5-py2.7.egg-info/ can fix the problem:

sudo rm -rf MySQL_python-1.2.5-py2.7.egg-info/

0
Reavitor1 Christian in real li On

This is a compatiability issue. What i did was put my mysql python to 1.2.4b.4.

If you have mysqldb installed uninstall with

pip uninstall MySQL-python

then install with same version:

pip install mysql-python==1.2.4b4

This is the beta hence the b

This works for me. I tested by going into python interactive with python

then import MySQLdb and it worked. Hope this helps