0

For me mysql db has been successfully instaled in my system.I verified through the following code that it is successfully installed without any errors.

C:\Python26>python
Python 2.6.1 (r261:67517, Dec  4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>>

But when I imported the mysqldb in my script its giving No module name MySQLdb.

Kindly let me know the problem and the solution..

I am using python 2.6 and mysql is 4.0.3 in windows XP.

Thanks in advance...

2
  • 1
    Your question states that you're using v2.6, but the interpreter says it's v2.4.1. If your script really is using v2.6, mysql might have been installed in the wrong site-packages folder. Commented Jul 17, 2009 at 7:48
  • That or you forgot to install the MySQL-python package. yast2 will do that for you. Commented Jul 17, 2009 at 8:03

2 Answers 2

2

1) Try using your package manager to download python-mysql which includes MySQLdb.

2) Ensure /usr/lib/python2.4/site-packages/ is in your PYTHONPATH, e.g.:

>>> import sys
>>> from pprint import pprint
>>> pprint(sys.path)
['',
 '/usr/lib/python2.4',
 '/usr/lib/python2.4/plat-linux2',
 '/usr/lib/python2.4/lib-tk',
 '/usr/lib/python2.4/site-packages']

3) You seem to be using the correct capitalization in your example, but it bears mentioning that the module name is case-sensitive, i.e. MySQLdb (correct) != mysqldb (incorrect).

Edit: Looks like nilamo has found the problem. As mentioned in a comment: you might be running your script with Python 2.6, but MySQLdb is installed in 2.4's site-packages directory.

Sign up to request clarification or add additional context in comments.

Comments

0

Since you show you are running linux, but you mention that mysql is running on windows, I suspect that you don't have MySQL, or the MySQL libraries or Python bindings, installed on the linux machine.

1 Comment

Hi Kevin, its my mistake to paste the code wrongly.Below is the proper code. C:\Python26>python Python 2.6.1 (r261:67517, Dec 4 2008, 16:51:00) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import MySQLdb >>>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.