python操作mysql数据库系列-安装MySQLdb
一波三折,先是pip命令出现问题,然后各种方法尝试解决。然后是直接使用pip2命令安装报错,mysql-python库安装再次出现问题。于是使用国内镜像的方式去安装:pip2 install MySQL-python -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com 这个命令去安装,总算链接上了,下载下来了,但是依然有报错。
pymongo 换成你想要安装的包,,别照搬照抄哈~~~~~~
报错如下:
针对这个问题,我们再次寻找解决方法,报错原因是因为我们缺少了一个文件 MySQL_python-1.2.5-cp27-none-win_amd64.whl 这个文件的下载地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#mysql-python
根据自己的操作系统版本选择下载的文件类型。我是选择的62位的。下载完成后,我们使用pip命令去安装刚刚下载的mysql文件。
再当前目录我们执行: pip2 install MySQL_python-1.2.5-cp27-none-win_amd64.whl 命令 如下图表示安装成功。
然后我们在去执行:pip2 install MySQL-python -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
发现已经安装成功了。然后我们进入到python2的交互模式,执行 import MySQLdb 发现导入成功!!!!
方案二:直接下载 MySQLdb for python(32/64位)下载地址:http://www.codegood.com/archives/129
在安装MySQL-python-1.2.3.win-amd64-py2.7.exe时,提示:Python version 2.7 required,which was not found in the registry
这是在注册表不能识别python2.7,原因windows是64位,安装的python是32位。怎么查看自己安装的python是多少位的呢?因为32位、64位都可以在64位操作系统中安装,所以年代久远的时候,就不记得当时自己安装的python是32呢,还是64了。查看非常之简单。输入平时我们检查是否有python环境的命令即可:
C:\Users\Administrator>python
MySQLdb for python(32/64位)下载地址:http://www.codegood.com/archives/129
解决方法:
1.新建一个register.py文件,将如下代码copy进去:

#
# 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.定位到该文件所在目录运行python register.py
说明python2.7已经注册成功。
3.再执行MySQLdb安装程序,则会自动识别,并安装成功了。
注意:目前Mysqldb这个模块 不支持python3环境,所以我们的安装教程是以python2为主。
python操作mysql数据库系列-安装MySQLdb的更多相关文章
- Python学习(20)python操作mysql数据库_安装
win7系统下python3.4连接mysql数据库 1.到python官方网站下载最新python程序.根据系统有32,64位. 直接下一步,就可以安装成功. 2.在python官网中去下载 ...
- python操作mysql数据库系列-操作MySql数据库(二)
接口测试框架层级目录结构示意图: page目录下面的mysqlTest.py:存放的是mysql的操作代码 utils目录下面的helper.py:存放的是公共的配置方法 log目录log.md:存放 ...
- Windows下安装MySQLdb, Python操作MySQL数据库的增删改查
这里的前提是windows上已经安装了MySQL数据库,且配置完成,能正常建表能操作. 在此基础上仅仅需安装MySQL-python-1.2.4b4.win32-py2.7.exe就ok了.仅仅有1M ...
- python操作三大主流数据库(1)python操作mysql①windows环境中安装python操作mysql数据库的MySQLdb模块mysql-client
windows安装python操作mysql数据库的MySQLdb模块mysql-client 正常情况下应该是cmd下直接运行 pip install mysql-client 命令即可,试了很多台 ...
- python操作mysql数据库的常用方法使用详解
python操作mysql数据库 1.环境准备: Linux 安装mysql: apt-get install mysql-server 安装python-mysql模块:apt-get instal ...
- 【转】python操作mysql数据库
python操作mysql数据库 Python 标准数据库接口为 Python DB-API,Python DB-API为开发人员提供了数据库应用编程接口. Python 数据库接口支持非常多的数据库 ...
- Python操作MySQL数据库9个实用实例
用python连接mysql的时候,需要用的安装版本,源码版本容易有错误提示.下边是打包了32与64版本. MySQL-python-1.2.3.win32-py2.7.exe MySQL-pytho ...
- python接口自动化(三十八)-python操作mysql数据库(详解)
简介 现在的招聘要求对QA人员的要求越来越高,测试的一些基础知识就不必说了,来说测试知识以外的,会不会一门或者多门开发与语言,能不能读懂代码,会不会Linux,会不会搭建测试系统,会不会常用的数据库, ...
- Python 操作MySQL 数据库
Python 操作 MySQL 数据库 Python 标准数据库接口为 Python DB-API,Python DB-API为开发人员提供了数据库应用编程接口. Python 数据库接口支持非常多的 ...
随机推荐
- UUID是如何保证全局唯一的
UUID由以下几部分的组合: (1)当前日期和时间,UUID的第一个部分与时间有关,如果你在生成一个UUID之后,过几秒又生成一个UUID,则第一个部分不同,其余相同. 据说时间粒度很 ...
- 第四章.使用ant编译hadoop eclipse插件
从hadoop 0.20.203以后,hadoop的发布包里,不再对eclipse插件进行jar包发布,而是给出了打包的代码,需要各位开发人员自己进行打包和设置.我们打的包必须跟自己使用的hadoop ...
- 导出ExcelDemo
public String exportExcel(){ String message=null; SimpleDateFormat df =new SimpleDateFormat("yy ...
- 渗透辅助神器 - DZGEN
项目地址:https://github.com/joker25000/DZGEN git clone ┌─[root@sch01ar]─[/sch01ar] └──╼ #git clone https ...
- shell 入门基础
一. Shell变量 1. 变量可分为两类: 环境变量(全局变量) 和 局部变量 . 环境变量 : 所有的环境变量都是系统全局变量,可用于所有子进程中,这包括编辑器.shell脚本和各类应用 . 环境 ...
- Mysql总结(二)
数据库.表.字段.行 问:查询姓黄或洪的男生分析:数据从哪来,哪个表stu条件:姓黄或洪name or and 男生gender答:select * from stu where gender=1 a ...
- C# 在根据窗体中的表格数据生成word文档时出错
出错内容为:
- **深入了解lambda
之前已经了解过lambda了,但是在学习了闭包之后,我们有必要在探讨一下lambda(匿名函数). 匿名函数本质上就是一个函数,它所抽象出来的东西是一组运算. 它的使用场景就是:你在某处就真的只需要使 ...
- BLE 周边设备断开
运行中,突然远程设备断开. TBluetoothLEDevice.IsConnected 为false了. 再次搜索,订阅, BluetoothLE1.SubscribeToCharacteristi ...
- sql开启xp_cmdshell
sql开启xp_cmdshell sp_configure reconfigure go sp_configure reconfigure go