Reputation:
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...
Upvotes: 0
Views: 430
Reputation: 169264
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.
Upvotes: 2
Reputation: 7297
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.
Upvotes: 0