搜索
首页后端开发Python教程安装MySQLdb时遇到报错的情况及解决方案

这篇文章主要介绍了Windows下安装python MySQLdb遇到的问题及解决方法,需要的朋友可以参考下

片头语:因为工作需要,在CentOS上搭建环境MySQL+Python+MySQLdb,个人比较习惯使用Windows系统的操作习惯,对纯字符的OS暂时还不太习惯,所以,希望能在Windows系统上也搭建一个类似的环境,用于开发。下面介绍的是在Windows环境下编译MySQLdb的过程。补充一句:最近在网上搜索到一个MySQLdb的Windows安装包,使用起来会更方便一些,地址:http://www.codegood.com/archives/4

mysql-connector-python是MySQL官网提供的专门连接python的驱动程序;使用起来很方便。文件里面有很多程序实例供参考。

手工编译MySQLdb的过程如下:

下面列举出上面需要用到的软件的下载地址:

 MySQL - www.mysql.com/  64796f9d4ab7bc88db8307d028b60916

Python - www.python.org/  fb26738de0c3dd9fa043814c8ba9917b

MySQLdb - sourceforge.net/projects/mysql-python/  b043e52b8ef0558141a8d90b8f9569ca

1、安装MySQL,选择Custom,然后将“C Include Files / Lib Files”勾选上,如果使用Typical,则会出现问题(1),后面的配置也基本上都是默认选项,除了额外将"添加到系统路径"(Include Bin Directory in Windows PATH)这个复选框勾上。如果你对安装MySQL不是很清楚,可以从网上搜索一下,相关的文章很多

2、安装Python,也基本上默认的选项,只是把安装路径稍微改了一下。Python的默认安装路径是"C:/Python26",个人习惯将其改为"C:/Program Files/Python26"

3、在安装MySQLdb之前必须安装setuptools,要不然会出现编译错误。

Setuptools - http://pypi.python.org/pypi/setuptools   b43e4ff680d4ce107c8fe412ce5c8ed8

默认安装这个工具即可...

好了,可以正式开始安装MySQLdb了,我们下载的这个tar.gz是源码包,里面是没有安装程序的,需要先编译,再安装。3c8c29d3d405913cb1674d619ab809a8

(1)将MySQL-python-1.2.3.tar.gz解压到当前目录下,会出现一个MySQL-python-1.2.3文件夹;

(2)WIN+R,打开运行对话框,输入cmd,打开MS-DOS,进入上面解压的那个文件夹;(前提是你得明白cd是什么命令 :-)....)

(3)输入setup.py build开始编译...3e11cec463b35fec57c405ae5575904a

我在编译过程中遇到以下问题:

1)问题: _mysql.c(34) : fatal error C1083: Cannot open include file: ‘config-win.h': No such file or directory
error: command ‘”C:/Program Files/Microsoft Visual Studio 9.0/VC/BIN/cl.exe”‘ failed with exit status 2

原因:原因是安装MySQL的时候没有安装C语言库。

解决:重新运行MySQL的安装程序,选择Modify,把“C Include Files / Lib Files”勾选上,并安装。

2)问题:Traceback (most recent call last):
  File "setup.py", line 15, in 4225fa317875f3e92281a7b1a5733569
    metadata, options = get_config()
  File "C:/MySQL-python-1.2.3/setup_windows.py", line 7, in get_config
    serverKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, options['registry_key'])
WindowsError: [Error 2] The system cannot find the file specified

原因:MySQL for python 1.2.3仍然是在寻找MySQL5.0的版本

解决:1、打开目录下site.cfg文件,修改最后一行为“registry_key = SOFTWARE/MySQL AB/MySQL Server 5.1”
2、打开setup_windows.py文件,修改第七行为“serverKey = _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, 'SOFTWARE/MySQL AB/MySQL Server 5.1')”

3)问题:build/temp.win32-2.7/Release/_mysql.pyd.manifest : general error c1010070: Failed to load and parse the manifest. The system cannot find the file specified.
error: command ‘mt.exe' failed with exit status 31

原因:路径发生变化?

解决:打开“你的PYTHON安装目录/Lib/distutils/msvc9compiler.py”文件,找到“ld_args.append('/MANIFESTFILE:' + temp_manifest)”这行代码,将其改为“ld_args.append('/MANIFEST')”

(4)当编译完成以后,就可以输入setup.py install了,现在终于大功告成了!

可以在DOS环境下输入以下命令进行测试:

C:/Users/Michael>python
Python 2.6.6 (r266:84297, Aug 24 2010, 18:46:32) [MSC v.1500 32 bit (Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>>

【相关推荐】

1. Python免费视频教程

2. python遇见数据采集视频教程

3. python学习手册

以上是安装MySQLdb时遇到报错的情况及解决方案的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
Python:深入研究汇编和解释Python:深入研究汇编和解释May 12, 2025 am 12:14 AM

pythonisehybridmodelofcompilationand interpretation:1)thepythoninterspretercompilesourcececodeintoplatform- interpententbybytecode.2)thepytythonvirtualmachine(pvm)thenexecuteCutestestestesteSteSteSteSteSteSthisByTecode,BelancingEaseofuseWithPerformance。

Python是一种解释或编译语言,为什么重要?Python是一种解释或编译语言,为什么重要?May 12, 2025 am 12:09 AM

pythonisbothinterpretedAndCompiled.1)它的compiledTobyTecodeForportabilityAcrosplatforms.2)bytecodeisthenInterpreted,允许fordingfordforderynamictynamictymictymictymictyandrapiddefupment,尽管Ititmaybeslowerthananeflowerthanancompiledcompiledlanguages。

对于python中的循环时循环与循环:解释了关键差异对于python中的循环时循环与循环:解释了关键差异May 12, 2025 am 12:08 AM

在您的知识之际,而foroopsareideal insinAdvance中,而WhileLoopSareBetterForsituations则youneedtoloopuntilaconditionismet

循环时:实用指南循环时:实用指南May 12, 2025 am 12:07 AM

ForboopSareSusedwhenthentheneMberofiterationsiskNownInAdvance,而WhileLoopSareSareDestrationsDepportonAcondition.1)ForloopSareIdealForiteratingOverSequencesLikelistSorarrays.2)whileLeleLooleSuitableApeableableableableableableforscenarioscenarioswhereTheLeTheLeTheLeTeLoopContinusunuesuntilaspecificiccificcificCondond

Python:它是真正的解释吗?揭穿神话Python:它是真正的解释吗?揭穿神话May 12, 2025 am 12:05 AM

pythonisnotpuroly interpred; itosisehybridablectofbytecodecompilationandruntimeinterpretation.1)PythonCompiLessourceceCeceDintobyTecode,whitsthenexecececected bytybytybythepythepythepythonvirtirtualmachine(pvm).2)

您可以使用Python中的循环加入列表吗?您可以使用Python中的循环加入列表吗?May 10, 2025 am 12:14 AM

是的,YouCanconCatenatElistsusingAloopInpyThon.1)使用eparateLoopsForeachListToAppendIteMstoaresultList.2)useanestedlooptoiterateOverMultipliplipliplipliplipliplipliplipliplipliplistforamoreConciseApprace.3)

condenate列表python:使用,扩展()等condenate列表python:使用,扩展()等May 10, 2025 am 12:12 AM

ThemostefficientmethodsforconcatenatinglistsinPythonare:1)theextend()methodforin-placemodification,2)itertools.chain()formemoryefficiencywithlargedatasets.Theextend()methodmodifiestheoriginallist,makingitmemory-efficientbutrequirescautionifpreserving

Python循环:示例和最佳实践Python循环:示例和最佳实践May 10, 2025 am 12:05 AM

pythonboopsincludeforandwhileloops,with forloopsidealforequencessand and whileloopsforcondition repetition.bestpracticesinvolve:1)使用listComprehensionsforshensionsforsimpletranspletransformations,2)obseringEnumerateForIndex-valuepairs,3)optingftingftingfortermornemoremoremoremore

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

适用于 Eclipse 的 SAP NetWeaver 服务器适配器

将Eclipse与SAP NetWeaver应用服务器集成。

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

功能强大的PHP集成开发环境