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安 ...
随机推荐
- simpson公式求定积分(模板)
#include<cstdio> #include<cmath> #include <algorithm> using namespace std; double ...
- 【BZOJ3879】SvT 后缀数组+单调栈
[BZOJ3879]SvT Description (我并不想告诉你题目名字是什么鬼) 有一个长度为n的仅包含小写字母的字符串S,下标范围为[1,n]. 现在有若干组询问,对于每一个询问,我们给出若干 ...
- 【Python之路】第十二篇--JavaScript
JavaScript 历史 1992年Nombas开发出C-minus-minus(C--)的嵌入式脚本语言(最初绑定在CEnvi软件中).后将其改名ScriptEase.(客户端执行的语言) Net ...
- ubuntu14.04 编译安装CPU版caffe
本文,试图中一个干净的ubuntu14.04机器上安装caffe的cpu版本. http://blog.csdn.net/sinat_35188997/article/details/735304 ...
- 10款最佳SQL Server服务器监控工具
转自:http://server.51cto.com/sSecurity-587355.htm 推荐 | 10款最佳SQL Server服务器监控工具 服务器是网络中最重要的资源之一,SQL Serv ...
- 010-JDK可视化监控工具-VisualVM
一.概述 VisualVM是一个集成多个JDK命令行工具的可视化工具.VisualVM基于NetBeans平台开发,它具备了插件扩展功能的特性,通过插件的扩展,可用于显示虚拟机进程及进程的配置和环境信 ...
- tensorflow 中 name_scope 及 variable_scope 的异同
Let's begin by a short introduction to variable sharing. It is a mechanism in TensorFlow that allows ...
- php strtotime 函数UNIX时间戳
int strtotime ( string time [, int now]) 本函数预期接受一个包含英文日期格式的字符串并尝试将其解析为 UNIX 时间戳. 如果 time 的格式是绝对时间则 n ...
- Sqrt(x)
这题没多大技巧性,只是牛顿迭代法多用于数值计算,这里出现有些意外.维基上有方法说明:http://zh.wikipedia.org/wiki/牛顿法 int sqrt(int x) { if (x = ...
- Notepad++ c编译环境 64
准备: mingw64(我是从西西软件园下的) 个人微盘共享地址: http://url.cn/24RAhTf notepad++ 安装 mingw64 系统path路径(bin目录下) Notepa ...