zoukankan      html  css  js  c++  java
  • ImportError: No module named MySQLdb 解决方案

    在用PyCharm执行py脚本过程中出现ImportError: No module named MySQLdb 错误,经过查看发现是没有安装mysqldb。

     
    环境:
            操作系统:WIN7 64位
            Python:Version 2.7
     
    1、安装Python2.7(步骤略)
    2、在环境变量的Path中配置Python2.7的安装路径

    3、下载MySQL-Python-1.2.3.win-amd64-py2.7.exe进行安装,可以在http://download.csdn.NET/detail/seven_zhao/6607625下载

    4、如果安装过程中出现python version 2.7 required,which was not found in the registry提示,并且下图中没有内容,则需要进行以下修复步骤

    5、修复步骤4的错误提示:复制下面代码,保存为register.py,执行register.py文件(用python shell打开,按F5执行),执行完后就会出现python2.7 is already registered提示(忘了截图,借的图)

    [python] view plain copy
     
     print?
    1.    
    2. import sys  
    3.    
    4. from _winreg import *  
    5.    
    6. # tweak as necessary  
    7. version = sys.version[:3]  
    8. installpath = sys.prefix  
    9.    
    10. regpath = "SOFTWARE\Python\Pythoncore\%s\" % (version)  
    11. installkey = "InstallPath"  
    12. pythonkey = "PythonPath"  
    13. pythonpath = "%s;%s\Lib\;%s\DLLs\" % (  
    14.     installpath, installpath, installpath  
    15. )  
    16.    
    17. def RegisterPy():  
    18.     try:  
    19.         reg = OpenKey(HKEY_CURRENT_USER, regpath)  
    20.     except EnvironmentError as e:  
    21.         try:  
    22.             reg = CreateKey(HKEY_CURRENT_USER, regpath)  
    23.             SetValue(reg, installkey, REG_SZ, installpath)  
    24.             SetValue(reg, pythonkey, REG_SZ, pythonpath)  
    25.             CloseKey(reg)  
    26.         except:  
    27.             print "*** Unable to register!"  
    28.             return  
    29.         print "--- Python", version, "is now registered!"  
    30.         return  
    31.     if (QueryValue(reg, installkey) == installpath and  
    32.         QueryValue(reg, pythonkey) == pythonpath):  
    33.         CloseKey(reg)  
    34.         print "=== Python", version, "is already registered!"  
    35.         return  
    36.     CloseKey(reg)  
    37.     print "*** Unable to register!"  
    38.     print "*** You probably have another Python installation!"  
    39.    
    40. if __name__ == "__main__":  
    41.     RegisterPy()  
     
    6、继续执行步骤4,一直到完成。
    7、此时再执行PyCharm中的脚本,如果出现”ImportError DLL load failed: %1 不是有效的 Win32 应用程序“错误提示则是因为安装的mysqldb是32位的MySql-python-1.2.3.win32-py2.exe,将其改成64位的再重新安装就可以了。
  • 相关阅读:
    素数路径Prime Path POJ3126 素数,BFS
    Fliptile POJ3279 DFS
    Find the Multiple POJ1426
    洗牌Shuffle'm Up POJ3087 模拟
    棋盘问题 POJ1321 DFS
    抓住那只牛!Catch That Cow POJ3278 BFS
    Dungeon Master POJ2251 三维BFS
    Splitting into digits CodeForce#1104A
    Ubuntu下手动安装Nvidia显卡驱动
    最大连续子序列和
  • 原文地址:https://www.cnblogs.com/browser/p/6879196.html
Copyright © 2011-2022 走看看