在Win7中使用Python的MySQLdb模块
2015-07-07 09:35
621 查看
概述:
Linux上对这一块的处理还是不错的,不过在Windows上就有一点小麻烦,麻烦的点不在于安装过程,而是在安装的过程中可能会有一些问题。步骤:
1.安装MySQLdb模块
我们在网上下载相应的MySQLdb的版本文件,例如我的就是MySQL-python-1.2.3.win-amd64-py2.7。此文件是exe文件,直接点击运行即可。2.解决python version 2.7 required,which was not found in the registry报错
在我想下载完MySQL-python-1.2.3.win-amd64-py2.7.exe进行安装时,程序给我报了这样一个错误信息:原因分析:
win7是64位的原因,在安装python时,如果选择只为当前用户,以上问题是不会出现的,如果选择所有用户,那就用上面的方法解决吧解决方法:
1.复制下面的代码,保存至register.py:# # script to register Python 2.0 or later for use with win32all # and other extensions that require Python registry settings # # written by Joakim Loew for Secret Labs AB / PythonWare # # source: # http://www.pythonware.com/products/works/articles/regpy20.htm # # modified by Valentine Gogichashvili as described in http://www.mail-archive.com/distutils-sig@python.org/msg10512.html import sys from _winreg import * # tweak as necessary version = sys.version[:3] installpath = sys.prefix regpath = "SOFTWARE\\Python\\Pythoncore\\%s\\" % (version) installkey = "InstallPath" pythonkey = "PythonPath" pythonpath = "%s;%s\\Lib\\;%s\\DLLs\\" % ( installpath, installpath, installpath ) def RegisterPy(): try: reg = OpenKey(HKEY_CURRENT_USER, regpath) except EnvironmentError as e: try: reg = CreateKey(HKEY_CURRENT_USER, regpath) SetValue(reg, installkey, REG_SZ, installpath) SetValue(reg, pythonkey, REG_SZ, pythonpath) CloseKey(reg) except: print "*** Unable to register!" return print "--- Python", version, "is now registered!" return if (QueryValue(reg, installkey) == installpath and QueryValue(reg, pythonkey) == pythonpath): CloseKey(reg) print "=== Python", version, "is already registered!" return CloseKey(reg) print "*** Unable to register!" print "*** You probably have another Python installation!" if __name__ == "__main__": RegisterPy()
2.运行register.py,搞定。
3.解决DLL load failed: %1 不是有效的 Win32 应用程序报错
出现上述问题的原因是因为我们的Python和MySQLdb的版本不对应造成的。我的问题是Python是32位的,而MySQLdb却是64位的。
相关文章推荐
- Python学习之文件读写
- Python笔记:性能优化指南
- Python3爬虫爬取某网站美女图片
- yum 遇到 python运行问题
- Python自学笔记之函数式编程4——sorted
- Python 的一些高级特性
- boost.python编译及示例
- python unicode&str 转化
- Python中的urllib模块使用详解
- Python的多态性实例分析
- python生成IP段的方法
- python妹子图简单爬虫实例
- Python实现爬取逐浪小说的方法
- Python变量作用范围实例分析
- Python实现合并字典的方法
- python类和继承用法实例
- Python可变参数函数用法实例
- Python打印斐波拉契数列实例
- python 中的set与list,tuple
- Scrapy的安装_Python