MySQLdb and Python ImportError

I can’t let life show me. I’ve been searching the Internet all day and all resources seem terribly outdated. From what I can tell, getting MySQLdb and Python to play well together is pretty tricky. I figured it out, and I'm not sure how to move on.

First, I run Python 2.7

The error I get when I try to run "import MySQLdb" in the live interpreter is this:

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

I also see the following error logs when I run "pip install mysql-python", however I'm not sure thats jsut is due to an incorrect version match. http://pastebin.com/hqVv6aPZ

I have a python project that has a dependency on MySQLdb, and I'm trying to get virtualenv that I am running Python to install the package correctly. This is what I did:

  • I created MySQL from the source to make sure that I have a 64-bit compatible version of MySQL on my machine. For this, I used the -universal flag.
  • I verified that I am running a 64-bit version of Python.
  • MySQL came from Homebrew
  • mysql-python came from pip

For life, I cannot understand what to do here. It seems that there is only an incorrect version of the MySQLdb and _mysql versions on my machine. This is true? Should this solution just reinstall the old version of MySQL? It seems that when I force pip to install mysql-python version 1.2.5, it installs MySQLdb version 1.2.2, so I get lost about what to do here because I'm not sure which package from homebrew actually correlates with version 1.2 .5 for _mysql.

EDIT -

sys.path

 '/Users/XXXXXXXXXXX/virtualenvs/qa-automated-tests/lib/python27.zip', '/Users/XXXXXXXXXXX/virtualenvs/qa-automated-tests/lib/python2.7', '/Users/XXXXXXXXXXX/virtualenvs/qa-automated-tests/lib/python2.7/plat-darwin', '/Users/XXXXXXXXXXX/virtualenvs/qa-automated-tests/lib/python2.7/plat-mac', '/Users/XXXXXXXXXXX/virtualenvs/qa-automated-tests/lib/python2.7/plat-mac/lib-scriptpackages', '/Users/XXXXXXXXXXX/virtualenvs/qa-automated-tests/Extras/lib/python', '/Users/XXXXXXXXXXX/virtualenvs/qa-automated-tests/lib/python2.7/lib-tk', '/Users/XXXXXXXXXXX/virtualenvs/qa-automated-tests/lib/python2.7/lib-old', '/Users/XXXXXXXXXXX/virtualenvs/qa-automated-tests/lib/python2.7/lib-dynload', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac', '/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages', '/Users/adam.stark/virtualenvs/qa-automated-tests/lib/python2.7/site-packages' 

Python --version says I'm on version 2.7.5. I also installed pastebin for the public. I'm just not sure what exactly is appropriate in this dump, it spits out 16 errors.

+5
source share
4 answers

The problem here was a few. As Abarner noted in the comments on the question, there was a mixture of system python and virtual python. To solve this problem, I had to change the properties of the PyDev project to only point to a virtual python instance, and then in the PyDev interpreter settings I had to rebuild PYTHONPATH.

After that, in virtualenv, I had to run the following code:

 pip uninstall mysql-python pip install mysql-python==1.2.5 

This solved all the problems.

+4
source

You can try this. Open a terminal and enter:

 sudo apt-get remove python-mysqldb sudo apt-get install python-dev libmysqlclient-dev git clone https://github.com/farcepest/MySQLdb1.git python setup.py build sudo python setup.py install 

It worked for me. I am using Python 2

+1
source

I had the same issue, produced for a different reason. I do not have root privileges on my working machine (part of the university infrastructure). I had to install MySQLdb locally by releasing pip install --user MySQL-python (from this manual ). This led to the same ImportError: this is MySQLdb version (1, 2, 3, 'final', 0), but _mysql is version (1, 2, 5, 'final', 1) mismatch. Installing version 1.2.5 did not work.

What I did: remove from local and reinstall version 1.2.3 as indicated by error

pip install --user MySQL-python==1.2.3

The error has disappeared.

0
source

do it and try again

 pip uninstall mysqlclient 
0
source

Source: https://habr.com/ru/post/1244608/


All Articles