windows 环境下安装python MySQLdb
Linux下MySQLdb安装见
http://blog.csdn.NET/wklken/article/details/7271019
-------------------------------------------------------------
以下是windows环境下的:
1. 安装数据库mysql
下载地址:http://www.mysql.com/downloads/
可以顺带装个图形工具,我用的是MySQL-Front
2. 安装MySQLdb
好了,到了这一步,你有两个选择
A. 安装已编译好的版本(一分钟)
B. 从官网下,自己编译安装(介个…..半小时到半天不等,取决于你的系统环境以及RP)
若是系统32位的,有c++编译环境的,自认为RP不错的,可以选择自己编译安装,当然,遇到问题还是难免的,一步步搞还是能搞出来的
若是系统64位的,啥都木有的,建议下编译版本的,甭折腾
2.1安装已编译版本:
http://www.codegood.com/downloads
根据自己系统下载,双击安装,搞定
然后import MySQLdb,查看是否成功
我的,win7,64位,2.7版本
MySQL-python-1.2.3.win-amd64-py2.7.exe
2.2自己编译安装
话说搞现成的和自己编译差距不一一点半点的,特别是64位win7,搞死了
2.2.1安装setuptools
在安装MySQLdb之前必须安装setuptools,要不然会出现编译错误
http://pypi.python.org/pypi/setuptools
http://peak.telecommunity.com/dist/ez_setup.py 使用这个安装(64位系统必须用这个)
2.2.2安装MySQLdb
下载MySQLdb
http://sourceforge.net/projects/mysql-python/
解压后,cmd进入对应文件夹
如果32位系统且有gcc编译环境,直接
python setup.py build
2.2.3问题汇总
A. 64位系统,无法读取注册表的问题
异常信息如下:
F:\devtools\MySQL-python-1.2.3>pythonsetup.py build
Traceback (most recent call last):
File "setup.py", line 15, in <module>
metadata, options = get_config()
File "F:\devtools\MySQL-python-1.2.3\setup_windows.py", line7, in get_config
serverKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, options[' registry_ke
y'] )
WindowsError: [Error 2] The system cannotfind the file specified
解决方法:
其实分析代码,发现只是寻找mysql的安装地址而已 修改setup_windows.py如下
注解两行,加入一行,为第一步mysql的安装位置
#serverKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE,options['registry_key'] )
#mysql_root, dummy = _winreg.QueryValueEx(serverKey,'Location')
mysql_root = r"F:\devtools\MySQL\MySQL Server 5.5"
B.没有gcc编译环境
unable to find vcvarsall.bat
解决方法:安装编译环境(一个老外的帖子)
1) First ofall download MinGW. Youneed g++compiler and MingW make in setup.
2) If youinstalled MinGW for example to “C:\MinGW” then add “C:\MinGW\bin”to your PATH in Windows.(安装路径加入环境变量)
3) Now startyour Command Prompt and Go the directory where you have your setup.py residing.
4) Last andmost important step:
setup.py install build --compiler=mingw32
或者在setup.cfg中加入:
[build]
compiler = mingw32
C.gcc: /Zl: No suchfile or directory错误
异常信息如下
F:\devtools\MinGW\bin\gcc.exe -mno-cygwin-mdll -O -Wall -Dversion_info=(1,2,3,'
final',0) -D__version__=1.2.3"-IF:\devtools\MySQL\MySQL Server 5.5\include" -IC
:\Python27\include -IC:\Python27\PC -c_mysql.c -o build\temp.win-amd64-2.7\Rele
ase\_mysql.o /Zl
gcc: error: /Zl: No such file or directory
error: command 'gcc' failed with exitstatus 1
参数是vc特有的编译参数,如果使用mingw的话因为是gcc所以不支持。可以在setup_windows.py中去掉
/Zl
解决方法:
修改setup_windows.py 改为空的
#extra_compile_args = [ '/Zl' ]
extra_compile_args = [ '' ]
目前就遇到这几个问题,望补充
3. 增删改查代码示例及结果(just for test)
- CREATE TABLE `user` (
- `Id` int(11) NOT NULL AUTO_INCREMENT,
- `name` varchar(255) DEFAULT NULL,
- `age` varchar(255) DEFAULT NULL,
- PRIMARY KEY (`Id`)
- ) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;
- #-*- coding:utf-8 -*-
- #dbtest.py
- #just used for a mysql test
- '''''
- Created on 2012-2-12
- @author: ken
- '''
- #mysqldb
- import time, MySQLdb, sys
- #connect
- conn=MySQLdb.connect(host="localhost",user="root",passwd="test_pwd",db="school",charset="utf8")
- cursor = conn.cursor()
- #add
- sql = "insert into user(name,age) values(%s,%s)"
- param = ("tom",str(20))
- n = cursor.execute(sql,param)
- print n
- #更新
- sql = "update user set name=%s where Id=9001"
- param = ("ken")
- n = cursor.execute(sql,param)
- print n
- #查询
- n = cursor.execute("select * from user")
- for row in cursor.fetchall():
- for r in row:
- print r,
- print ""
- #删除
- sql = "delete from user where name=%s"
- param =("ted")
- n = cursor.execute(sql,param)
- print n
- cursor.close()
- #关闭
- conn.close()

windows 环境下安装python MySQLdb的更多相关文章
- 从零开始Windows环境下安装python+tensorflow
从零开始Windows环境下安装python+tensorflow 2017年07月12日 02:30:47 qq_16257817 阅读数:29173 标签: windowspython机器学习te ...
- windows环境下安装python模块大招
python发展到今天,感觉版本有点控制不住了,同时出现多个版本python2.5,python2.7 python 3 ,同时跨越windows,mac,*inux等多个平台,还有32位,64位等不 ...
- Python Windows环境下安装Python集成开发环境 学习之路(一)
一.安装下载安装 Python https://www.python.org/ 全部下一步,直接Finish PyCharm http://www.jetbrains.com/pycharm/ 全部 ...
- windows环境下安装Python的Rtree包
Rtree包是基于libspatialindex开发的,在安装Rtree之前必须先安装libspatialindex.关于libspatialindex,除了官网的英文外,这里有一个中文翻译过来的介绍 ...
- 在 windows 环境下安装 redislive
这是一篇在 windows 环境下安装 redislive 的教程! 项目地址:https://github.com/nkrode/RedisLive 配置文档:http://www.nkrode.c ...
- 4.1. 如何在Windows环境下开发Python
4.1. 如何在Windows环境下开发Python 4.1. 如何在Windows环境下开发Python 4.1.1. Python的最原始的开发方式是什么样的 4.1.1.1. 找个文本编辑器,新 ...
- cygwin 下安装python MySQLdb
cygwin 下安装python MySQLdb 1) cygwin 更新 运行 cygwin/setup-x86_64.exe a 输入mysql,选择下面的包安装: libmysqlclient- ...
- Django框架学习笔记(windows环境下安装)
博主最近开始学习主流框架django 网上大部分的安装环境都linux的 由于博主在windows环境下已经有了 Pycharm编辑器 ,所以决定还是继续在windows环境下学习 首先是下载 链接 ...
- Linux 环境下安装python相关
目录 Linux 环境下安装python相关 linux软件包管理工具之yum工具(如同pip3工具) yum源理解 下载阿里云的.repo仓库文件 ,放到/etc/yum.repos.d/ yum安 ...
随机推荐
- poj3243 Clever Y[扩展BSGS]
Clever Y Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 8666 Accepted: 2155 Descript ...
- [LeetCode] Reverse Lists
Well, since the head pointer may also be modified, we create a new_head that points to it to facilit ...
- 160714、解决虚拟机上的tomcat无法被主机访问的问题
备注:我虚拟机是centos 6.5 在wmware中安装linux后安装好数据库,JDK及tomcat后启动服务,虚拟机中可以访问,但是主机却无法访问,但是同时主机和虚拟机之间可以ping的通 ...
- JAVA源码之JDK(三)——String、StringBuffer、StrinBuilder
Java中,除了8种基本类型,最长用的应该就是String类了.那么我们来看看JDK中的源码是怎么建造String.StringBuffer.StrinBuilder一系列类的. java.lang. ...
- HTML5 云知梦自觉,记录知识 点
第一章(1--3) 文档类型:<!doctype html> 网站代码结构:<html> <head> <meta charset="UTF-8&q ...
- javascript数组中的方法
数组中的方法 今天我们来说一下,对数组进行操作的几种方法: //添加 a=[];//空数组 a[0]="我是第一个"; a[2]="我是第三个"; ...
- 【转】va_list 详解
原文出自http://www.cppblog.com/xmoss/archive/2009/07/20/90680.html VA_LIST 是在C语言中解决变参问题的一组宏 他有这么几个成员: 1) ...
- 数据库、Java与Hibernate数据类型对照
数据类型对照表: 标准SQL数据类型 Java数据类型 Hibernate数据类型 TINYINT byte.java.lang.Byte byte SMALLINT short.java.lang. ...
- (转载)处理SQL解析失败导致share pool 的争用
通过关联x$kglcursorx$kglcursor_child_sqlid视图: 通过使用Oracle10035Event事件可以找到解析失败的SQL: 通过oraclesystemdump也可以找 ...
- 用python的turtle画分形树
由于分形树具有对称性,自相似性,所以我们可以用递归来完成绘制.只要确定开始树枝长.每层树枝的减短长度和树枝分叉的角度,我们就可以把分形树画出来啦!! 代码如下: # -*- coding: utf-8 ...