在Win7中使用Python的MySQLdb模块
2015-07-07 09:35
585 查看
概述:
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动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- Win7 不能运行bat
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法