Python 2.7.1 import MySQLdb working via cmd but no in a .py file
Question: Okay, i have Python2.7.1 installed in a windows 32.

The problem is, when i try to import MySQLdb module via python in cmd,

python recognizes the module well,

but when i try the same script in a python file i got: ImportError: No module
named 'MySQLdb'

Anyone have faced same issue ?

Just to make more clear. Via cmd:

C:\Users\Desktop>python Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015,
20:32:19) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright",
"credits" or "license" for more information.

> > > import MySQLdb

via .py file C:\Users\Desktop>TesteDB12.py Traceback (most recent call last):
File "C:\Users\fs0222\Desktop\TesteDB12.py", line 1, in import MySQLdb
ImportError: No module named 'MySQLdb'

By the way i had python 3.5 before on my machine but i already changed my
enviroment variables to fit python 2.7, i flush the cache, restarted my
machine, tryed python mysqldb installers .exe .msi, and still the same
problem.

By the way couple months ago i was able to use this module normally.

Any helps ? Thanks a lot...


Answer: Specify the source path of python(.exe) in the first line of your python code

May be as follows:

    
    
    #!C:\Python26\python.exe
    
    import MySQLdb
    

