您的位置:首页 > 编程语言 > Python开发

Windows下Python添加MySQLdb扩展模块

2014-06-19 11:55 483 查看
转载来自:http://www.biaodianfu.com/python-error-unable-to-find-vcvarsall-bat.html

在安装一些Python模块时,大部分是cpython写的模块时会发生如下错误 error: Unable to find vcvarsall.bat。先前的一篇文章:在Windows上安装Scrapy时也讲到了这个问题。当时讲到的方案是,安装VS
2008进行解决,但是Vs 2008又太大,不想装,所以这次想到了另外的方案,同样是上次说的,当时上次很不完整。


解决方案一:安装Vs2008(实测)

完全的无脑流,安装完问题直接解决。


解决方案二:安装Vs2010(未测试)

上次在电脑上装个Vs2010并不能像 vs2008那样直接解决问题,从网上找到如下解决方案,不知是否可行。

打开“<python安装目录>\Lib\distutils\msvc9compiler.py”

找到 toolskey = “VS%0.f0COMNTOOLS” % version,直接修改为 toolskey = “VS100COMNTOOLS”


解决方案三:安装MinGW(实测)

1、下载安装MinGW,下载地址为:http://sourceforge.net/projects/mingw/files/latest/download?source=files

2、在MinGW的安装目录下找到bin文件夹,找到mingw32-make.exe,复制一份更名为make.exe

3、把MinGW的路径添加到环境变量path中,比如我把MinGW安装到D:\MinGW\中,就把D:\MinGW\bin添加到path中;

4、在<python安装目录>\distutils增加文件distutils.cfg,在文件里输入

[build]

compiler=mingw32

保存;

5、执行原先的模块安装,发现还是报错,报错内容为:error: command ‘gcc’ failed: No such file or directory 解决方案是将D:\MinGW\lib再添加到PATH中。

6、如果安装过程中出现 error: Could not find ‘openssl.exe’ 则直接到http://pypi.python.org/pypi/pyOpenSSL/0.13 下载安装即可。

6、再次执行时安装模块时,发现如下错误:

D:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall “-ID:\Program Files\Python27\inc

lude” “-ID:\Program Files\Python27\include” “-ID:\Program Files\Python27\PC” -c

../libdasm.c -o build\temp.win32-2.7\Release\..\libdasm.o

cc1.exe: error:unrecognized command line option ‘-mno-cygwin’

error: command ‘gcc’ failed with exit status 1

原因是gcc 4.6.x 以后不再接受-mno-cygwin为了解决这个问题需要修改<python安装目录>\distutils\cygwinccompiler.py文件。找到:

1234567self.set_executables(compiler='gcc -mno-cygwin -O -Wall', compiler_so='gcc -mno-cygwin -mdll -O -Wall', compiler_cxx='g++ -mno-cygwin -O -Wall', linker_exe='gcc', linker_so='%s -mno-cygwin %s %s' % (self.linker_dll, shared_option, entry_point))
修改为:

1

2

3

4

5

6

7

self.set_executables(compiler='gcc
-O -Wall',


compiler_so='gcc
-mdll -O -Wall',


compiler_cxx='g++
-mno-cygwin -O -Wall',


linker_exe='gcc',


linker_so='%s
-mno-cygwin %s %s'

%
(self.linker_dll,
shared_option,


entry_point))

至此,大功告成!
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: