Unable to import MySQLdb module in Python

I am trying to use MySQL in Python. I installed the MySQL adapter (MySQL-python-1.2.4b4.win32-py2.7) for Python, but when I try to import the MySQLdb module (import MySQLdb) using the command line, I get the following output:

Traceback (most recent call last): File "<stdin>", line 1, in <module> File "C:\Python27\lib\site-packages\MySQLdb\__init__.py", line 19, in <module> import _mysql ImportError: DLL load failed: %1 is not a valid Win32 application. 

Does anyone know what could be wrong?

+4
source share
3 answers

To use this adapter, you need a 32-bit version of Python. Which version are you using?

+7
source

I'm having trouble installing the 64-bit version of MySQLdb on Windows via Pip, but if you want to continue using the 64-bit version of Python and not revert to the 32-bit version, then you can install the compiled MySQLdb from the .whl file available from http://www.lfd.uci.edu/~gohlke/pythonlibs/

Then you will want to install the .whl file as a document in https://pip.pypa.io/en/latest/user_guide/#installing-from-wheels

+2
source

when you configure the module, be careful with the version of MySQL-python-1.2.3.win32-py2.7.exe and MySQL-python-1.2.4.win32-py2.7.exe, only one of 2 you need, try 2 times

-1
source

All Articles