tags:

views:

3785

answers:

6

Hi All I am using Python 2.6.1 and I want to connect to MySQLdb, I installed mySQL in my system, and I am trying to connect MySQL-python-1.2.2.win32-py2.6 from http://www.codegood.com/archives/4 site but its not working while running my application its saying that No module named MySQLdb

please any one provide me the proper setup for MySQLdb.

thanks in advance

+4  A: 

The module is not likely in your python search path..

Check to see if that module is in your Python Path... In windows...you may find it in the registry

HKLM\Software\Python\PythonCore\2.6\PythonPath

Be careful editing it...

You may also alter the Python Path programmaticly by the following

import sys
sys.path.append('somepath_to_the_module_you_wanted')

import the_module_you_wanted

Hope that helps

CMB
I'm having trouble getting my installation to connect to MySQL because of this same problem. Although your answer here may be correct, but do you guys honestly expect newbies to start tinkling with registry just to get Python working with MySQL? Your answer may be right but I think it's risky
Helen Neely
Helen, expressed in the above solution, there are two *TWO* means of solving your problem. (One of them does not involve registry editing) The first is an editing of your machine's python module search path. In windows, the module search path is located in registry and changes to it are *usually* done by the module installer.The second suggested solution suites your cautious nature. Python allows the python module search path to be modified (not permanently as in above) by code.Good luck
CMB
A: 

generally, (good) python modules provide a 'setup.py' script that takes care of things like proper installation (google for 'distutils python'). MySQLdb is a "good" module in this sense.

since you're using windows, things might be a bit more complex. I assume you already installed MySQLdb following the instructions and it still gives this problem. what I would do is open a cmd.exe window, cd to the directory containing the 'setup.py' script and there type something like C:\Python26\Python.exe setup.py install

if this does not work, then grab the module somewhere else, maybe at the place where it is actively developed: http://sourceforge.net/projects/mysql-python/

mariotomo
A: 

See this post on the mysql-python blog: MySQL-python-1.2.3 beta 2 released - dated March 2009. Looks like MySQLdb for Python 2.6 is still a work in progress...

Dave Everitt
Hi Everitt, I have downloaded has u specified link, but in that its not there setup file, actually I am using windows XPafter installation we need to set any path ? if its not what could be the reason for " No module named MySQLdb" ?
SKSK
Dave Everitt
+9  A: 

The best setup for Windows that I've found:

http://www.thescotties.com/mysql-python/test/

EDIT: Here's a more comprehensive list, that goes up to Python 2.7 as of 10/5/2010:

http://www.codegood.com/downloads

ojrac
Excellent link, that saved me a huge hassle. Thank you!
Dan Breen
Agree--thanks! (I was wary of installing from an unknown source, but that installer saved a ton of time.)
Dan
My thoughts exactly. Sketchy as it seemed, it saves so much time I just looked the other way.
ojrac
A: 

I was having this problem and then I realised I was importing MySQLdb erroneously - it's case sensitive:

Incorrect: >>>import mysqldb

Correct: >>>import MySQLdb

Silly mistake, but cost me a few hours!

clams1
A: 

thanks you guys! this has definitely helped! i have been scratching my head all day trying to build my own compiler. now i can focus on getting django started. thanks again!

Bright