I am trying to import MySQLdb in python. I checked and followed all possible solutions but I am still not able to import it. I have Windows 8.1.
So I started fresh, I installed the latest version of python (2.7.8), set the path and pythonpath variables, and then tried installing the MySQL-python-1.2.5.win-amd64-py2.7 from the link (https://pypi.python.org/pypi/MySQL-python/)
This is the error I get
>>> import MySQLdb
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named MySQLdb
I have tried searching and following many links. Nothing worked!! Can someone please help me with this.
Thanks
Issue resolved. I dint have a C compiler / Visual Studio in my laptop - This link might help http://mysql-python.blogspot.com/2012/11/is-mysqldb-hard-to-install.html I installed MinGW - http://sourceforge.net/projects/mingw/?source=typ_redirect Selected the c++ option
I uninstalled Anaconda, Python and Installed anaconda again. So python 2.7.7 got installed along with Anaconda. Did a conda init,
conda install pip
pip install mysql-python
and then import MySQLdb
No Error!! Hope this helps!!
====================================================================
Update - Jan 2, 2015
If you want to try installing mysql-python package using conda instead of pip, you can try the following, which worked for me.
conda install binstar
binstar search -t conda mysql-python
This will show you 10 different packages for different OS. krisvanneste mysql-python is for Win-64
To know more about this package use the command
binstar show krisvanneste/mysql-python
This will show you the command to install the mysql-python package which happens to be
conda install --channel https://conda.binstar.org/krisvanneste mysql-python
This will install the required package. Now trying import MySQLdb in python wont throw error.
来源:https://stackoverflow.com/questions/26705890/cannot-import-mysqldb-python-windows-8-1