一波三折,先是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的更多相关文章

  1. Python学习(20)python操作mysql数据库_安装

    win7系统下python3.4连接mysql数据库 1.到python官方网站下载最新python程序.根据系统有32,64位. 直接下一步,就可以安装成功.     2.在python官网中去下载 ...

  2. python操作mysql数据库系列-操作MySql数据库(二)

    接口测试框架层级目录结构示意图: page目录下面的mysqlTest.py:存放的是mysql的操作代码 utils目录下面的helper.py:存放的是公共的配置方法 log目录log.md:存放 ...

  3. Windows下安装MySQLdb, Python操作MySQL数据库的增删改查

    这里的前提是windows上已经安装了MySQL数据库,且配置完成,能正常建表能操作. 在此基础上仅仅需安装MySQL-python-1.2.4b4.win32-py2.7.exe就ok了.仅仅有1M ...

  4. python操作三大主流数据库(1)python操作mysql①windows环境中安装python操作mysql数据库的MySQLdb模块mysql-client

    windows安装python操作mysql数据库的MySQLdb模块mysql-client 正常情况下应该是cmd下直接运行 pip install mysql-client 命令即可,试了很多台 ...

  5. python操作mysql数据库的常用方法使用详解

    python操作mysql数据库 1.环境准备: Linux 安装mysql: apt-get install mysql-server 安装python-mysql模块:apt-get instal ...

  6. 【转】python操作mysql数据库

    python操作mysql数据库 Python 标准数据库接口为 Python DB-API,Python DB-API为开发人员提供了数据库应用编程接口. Python 数据库接口支持非常多的数据库 ...

  7. Python操作MySQL数据库9个实用实例

    用python连接mysql的时候,需要用的安装版本,源码版本容易有错误提示.下边是打包了32与64版本. MySQL-python-1.2.3.win32-py2.7.exe MySQL-pytho ...

  8. python接口自动化(三十八)-python操作mysql数据库(详解)

    简介 现在的招聘要求对QA人员的要求越来越高,测试的一些基础知识就不必说了,来说测试知识以外的,会不会一门或者多门开发与语言,能不能读懂代码,会不会Linux,会不会搭建测试系统,会不会常用的数据库, ...

  9. Python 操作MySQL 数据库

    Python 操作 MySQL 数据库 Python 标准数据库接口为 Python DB-API,Python DB-API为开发人员提供了数据库应用编程接口. Python 数据库接口支持非常多的 ...

随机推荐

  1. error while loading shared libraries: libaio.so.1: cannot open shared object file: No such file or directory

    编译出现如下错误: error while loading shared libraries: libaio.so.1: cannot open shared object file: No such ...

  2. 项目中Map端数据处理不均匀性分析

    Map任务的不均匀性 最近发现Map端数据越来越不均匀,而处理输入的数据,写到本地磁盘的数据量都差不多,我们随便拿出来两个attempt任务(当前map数量为64个),33和45,33的counter ...

  3. 文档主题生成模型(LDA)

    一.问题描述 1.1文本建模相关 统计文本建模的目的其实很简单:就是估算一组参数,这组参数使得整个语料库出现的概率最大.这是很简单的极大似然的思想了,就是认为观测到的样本的概率是最大的.建模的目标也是 ...

  4. 【洛谷】P1388 算式(dp)

    题目描述 给出N个数字,不改变它们的相对位置,在中间加入K个乘号和N-K-1个加号,(括号随便加)使最终结果尽量大.因为乘号和加号一共就是N-1个了,所以恰好每两个相邻数字之间都有一个符号.例如: N ...

  5. Ubuntu Server 16.04.1系统安装

    一.Ubuntu Server 16.04.1系统安装 Ubuntu分为桌面版(desktop)和服务器版(Server),下面为大家介绍服务器版本Ubuntu Server 16.04.1的详细安装 ...

  6. file_get_content服务器对服务器二进制文件上传

    1.file_get_contents函数可安全用于二进制对象,适用服务器对服务器文件是上传场景 base64_encode(file_get_contents('1268879774AaCl4wIE ...

  7. 浪潮openStack云

  8. jstack来分析linux服务器上Java应用服务性能异常

    使用jdk自带的jstack来分析linux服务器上应用服务性能异常: 1.top查找出哪个进程消耗的系统资源情况 [op1@jira ~]$ top top - 19:23:43 up 22 day ...

  9. leetcode419

    public class Solution { public int CountBattleships(char[,] board) { );//3行 );//4列 ; ; i < row; i ...

  10. Redis实战——安装问题汇总

    借鉴:https://www.cnblogs.com/liu2-/p/6914159.html 通用方法:迅速查看缺少的包的路径,并安装 yum provides *** 如 yum provides ...