TheAptKid
TheAptKid

Reputation: 1571

Can't import MySQLdb module in Python

I'm trying to use MySQL in Python. I have 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) with command prompt I receive 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.

Would anybody know, what could be wrong?

Upvotes: 6

Views: 6309

Answers (3)

kyrenia
kyrenia

Reputation: 5575

I had problems installing the 64-bit version of MySQLdb on Windows via Pip, but if you want to continue using a 64-bit version of Python, rather than reverting to a 32-bit version, then you can install the compiled MySQLdb from the .whl file available from http://www.lfd.uci.edu/~gohlke/pythonlibs/

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

Upvotes: 2

yongguangdu
yongguangdu

Reputation: 9

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

Upvotes: -1

Ketouem
Ketouem

Reputation: 3857

You need to have a 32bit version of Python to use this adapter. Which version are you actually using ?

Upvotes: 9

Related Questions