Cannot import MySQLdb - python - Windows 8.1

送分小仙女□ 提交于 2019-12-08 03:33:23

问题


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


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!