Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 490
TheAptKid Avatar asked Jan 10 '13 16:01

TheAptKid


People also ask

What is Python MySQLdb package?

MySQLdb is an interface for connecting to a MySQL database server from Python. It implements the Python Database API v2. 0 and is built on top of the MySQL C API. Packages to Install. mysql-connector-python mysql-python.


2 Answers

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

like image 196
Ketouem Avatar answered Sep 17 '22 03:09

Ketouem


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

like image 31
kyrenia Avatar answered Sep 18 '22 03:09

kyrenia