python2.7 mysql.connector的安装

来源:互联网 发布:崩坏学园淘宝店名 编辑:程序博客网 时间:2024/06/06 03:43


将pyton2.7 mysql.connector安装心得写下,供其他网友参考

1.去官网http://dev.mysql.com/downloads/connector/python   下载了 mysql-connector-python-2.1.3-py2.7-win32.msi 这个版本的进行安装

安装时却出现:


百度了一下,说什么需要自己一个register.py:

import sys  from _winreg import *  # tweak as necessaryversion = 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.我下载MySQL-python-1.2.5.win32-py2.7.exe 进行安装 ,安装 成功,但是些驱动的包是

import MYSQLdb

在网上查了一下,这个似乎被淘汰了。现在基本上都用mysql.connector

于是果断将其卸载,誓要将mysql.connector安装上

3.我换了个方向,不用官方的msi文件安装,想用源码来安装

果然在网上可以下载mysql.connector的源码  mysql-connector-python-1.2.3.zip

将其解压,看到了setup.py文件,那个激动呀,不说了

直接

python setup.py install
运行结果:
安装成功,文件写入了python2.7 安装目录下

看到有红色框的这两个文件,我就彻底安心了

运行 :>>python
>> import mysql.connector
完美,没有报错。

啦,啦,啦 ,到此,安装 成功


1 0
原创粉丝点击