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又太大,不想装,所以这次想到了另外的方案,同样是上次说的,当时上次很不完整。
完全的无脑流,安装完问题直接解决。
上次在电脑上装个Vs2010并不能像 vs2008那样直接解决问题,从网上找到如下解决方案,不知是否可行。
打开“<python安装目录>\Lib\distutils\msvc9compiler.py”
找到 toolskey = “VS%0.f0COMNTOOLS” % version,直接修改为 toolskey = “VS100COMNTOOLS”
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文件。找到:
修改为:
至此,大功告成!
在安装一些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=files2、在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文件。找到:
1234567 | self.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)) |
相关文章推荐
- Windows下Python添加MySQLdb扩展模块
- Windows下Python添加MySQLdb扩展模块
- Eclipse Pydev添加MySQLdb模块,Windows下安装MySQL-python
- Eclipse Pydev添加MySQLdb模块,Windows下安装MySQL-python
- windows(32位 64位)下python安装mysqldb模块
- python安装MySQLdb模块-(ubuntu,windows)
- Windows下Python添加库(模块)路径
- Python非官方扩展模块搜索方法(尤其是Windows平台下已编译好的模块)
- windows环境下安装Python的redis扩展模块
- Python扩展包安装方法以及Python添加库(模块)
- Windows下Python添加库(模块)路径
- Windows下Python添加库(模块)路径
- windows 下 python2.6的MySQLdb模块安装问题
- Windows下为Python编译C扩展模块
- windows下python 安装mysqldb模块
- windows环境下安装python的mysqldb模块
- 给Python中的MySQLdb模块添加超时功能的教程
- Windows下Python添加库(模块)路径
- Windows下Python添加库(模块)路径
- 给Python中的MySQLdb模块添加超时功能的教程