简体   繁体   English

无法导入MySQLdb-python-Windows 8.1

[英]Cannot import MySQLdb - python - Windows 8.1

I am trying to import MySQLdb in python. 我正在尝试在python中导入MySQLdb。 I checked and followed all possible solutions but I am still not able to import it. 我检查并遵循了所有可能的解决方案,但仍无法导入。 I have Windows 8.1. 我有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/ ) 因此,我从头开始,我安装了最新版本的python(2.7.8),设置了路径和pythonpath变量,然后尝试从链接( httpshttps://support.microsoft.com/kb/https://github.com/my-python-1.2.5.win-amd64-py2.7 ://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 我的笔记本电脑中装有C编译器/ Visual Studio-此链接可能会帮助http://mysql-python.blogspot.com/2012/11/is-mysqldb-hard-to-install.html我安装了MinGW- http: //sourceforge.net/projects/mingw/?source=typ_redirect选择了c ++选项

I uninstalled Anaconda, Python and Installed anaconda again. 我卸载了Anaconda,Python,然后再次安装了anaconda。 So python 2.7.7 got installed along with Anaconda. 因此python 2.7.7与Anaconda一起安装。 Did a conda init, 做了一个conda init,

conda install pip 

pip install mysql-python

and then import MySQLdb 然后导入MySQLdb

No Error!! 没有错误! Hope this helps!! 希望这可以帮助!!

==================================================================== ================================================== ==================

Update - Jan 2, 2015 更新-2015年1月2日

If you want to try installing mysql-python package using conda instead of pip, you can try the following, which worked for me. 如果您想尝试使用conda而不是pip安装mysql-python软件包,则可以尝试以下对我有用的方法。

conda install binstar

binstar search -t conda mysql-python

This will show you 10 different packages for different OS. 这将为您显示10个用于不同OS的不同软件包。 krisvanneste mysql-python is for Win-64 krisvanneste mysql-python适用于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 这将向您显示安装mysql-python软件包的命令

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. 现在尝试在python中导入MySQLdb不会抛出错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM