windows7下安装python的mysqldb模块有很多的坑,本文先介绍一下正确的安装方法:
1.先确认系统环境 (系统win7 64位,python 2.7.14
64位)
windowns 7 x64位

python 2.7.14

所以,我们安装python MySQLdb就必须选择 64位的: MySQL-python-1.2.5.win-amd64-py2.7.exe
以下是安装步骤:
1.双击安装模块

2. 单击下一步

3.确认安装的路径,单击下一步

4.单击下一步,完成注册安装

5.单击完成

6.打开python测试

7.pycharm环境测试
以下是安装时出现的坑
1.安装时提示如下错误:
Python version 2.7 required, which was not found in the registry

解决方法:
建立一个文件 register.py 内容如下. 然后执行该脚本,即可解决。
-
#!/usr/bin/env python
-
# -*- coding:utf-8 -*-
-
# Author :Alvin.xie
-
# @Time :2017-11-20 14:33
-
# @file :register.py
-
-
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.出现下面错误是安装32位导致的错误,因为系统python是64位的,所以MySQLdb必须是64位。

3. 出现下面这个错误是系统需要安装的是
MySQLdb-1.2.5
下面简单介绍一下linux下安装MySQLdb
1.使用yum安装

2.测试
阅读(1422) | 评论(0) | 转发(0) |