Python 使用mingw构建第三方库 Unable to find vcvarsall.bat错误解决方法

Python 使用mingw构建第三方库 Unable to find vcvarsall.bat错误解决方法


注意:这里使用的mingw32位版本,如果你的电脑上安装的python amd64位版本,那么请使用mingw64位版本,这个很重要,如果版本不正确,那么会报如下错误。

1collect2.exe: 错误:ld 返回 1
2error: command 'gcc' failed with exit status 1


在编译第三方库时,如果第三方库需要编译C文件,那么就需要C编译器,python默认使用microsoft visual studio(VS)编译器编译项目,但是大多数电脑上都没有安装VS程序。这时候,就可以选择另一个轻量级方案(毕竟VS 3个G的安装文件有点得不偿失),使用mingw编译项目。

第一步,下载mingw,这个可以通过百度搜索下载。这里为大家提供一个已经下载好了的压缩文件下载地址

http://pan.baidu.com/s/1mgypfhY

第二步,解压缩mingw压缩文件到任意(不要加压缩到有空格和中文的目录下面)目录。比如D:\mingw下面

第三步,将mingw目录下面的bin文件夹加入到PATH环境变量中。

第四步,测试mingw是否可用


1gcc -v

通过以上成功安装mingw

那么如何通过mingw构建项目呢

很简单通过如下命令即可


1python setup.py build --compiler=mingw32
对就是以上命令这么简单。

以下是如果找不到C编译器得到的错误参考(以Tornado库为例)


001D:\workspace\tornado-3.2.1\tornado-3.2.1>python setup.py build
002running build
003running build_py
004creating build
005creating build\lib.win-amd64-2.7
006creating build\lib.win-amd64-2.7\tornado
007copying tornado\auth.py -> build\lib.win-amd64-2.7\tornado
008copying tornado\autoreload.py -> build\lib.win-amd64-2.7\tornado
009copying tornado\concurrent.py -> build\lib.win-amd64-2.7\tornado
010copying tornado\curl_httpclient.py -> build\lib.win-amd64-2.7\tornado
011copying tornado\escape.py -> build\lib.win-amd64-2.7\tornado
012copying tornado\gen.py -> build\lib.win-amd64-2.7\tornado
013copying tornado\httpclient.py -> build\lib.win-amd64-2.7\tornado
014copying tornado\httpserver.py -> build\lib.win-amd64-2.7\tornado
015copying tornado\httputil.py -> build\lib.win-amd64-2.7\tornado
016copying tornado\ioloop.py -> build\lib.win-amd64-2.7\tornado
017copying tornado\iostream.py -> build\lib.win-amd64-2.7\tornado
018copying tornado\locale.py -> build\lib.win-amd64-2.7\tornado
019copying tornado\log.py -> build\lib.win-amd64-2.7\tornado
020copying tornado\netutil.py -> build\lib.win-amd64-2.7\tornado
021copying tornado\options.py -> build\lib.win-amd64-2.7\tornado
022copying tornado\process.py -> build\lib.win-amd64-2.7\tornado
023copying tornado\simple_httpclient.py -> build\lib.win-amd64-2.7\tornado
024copying tornado\stack_context.py -> build\lib.win-amd64-2.7\tornado
025copying tornado\tcpserver.py -> build\lib.win-amd64-2.7\tornado
026copying tornado\template.py -> build\lib.win-amd64-2.7\tornado
027copying tornado\testing.py -> build\lib.win-amd64-2.7\tornado
028copying tornado\util.py -> build\lib.win-amd64-2.7\tornado
029copying tornado\web.py -> build\lib.win-amd64-2.7\tornado
030copying tornado\websocket.py -> build\lib.win-amd64-2.7\tornado
031copying tornado\wsgi.py -> build\lib.win-amd64-2.7\tornado
032copying tornado\__init__.py -> build\lib.win-amd64-2.7\tornado
033creating build\lib.win-amd64-2.7\tornado\test
034copying tornado\test\auth_test.py -> build\lib.win-amd64-2.7\tornado\test
035copying tornado\test\concurrent_test.py -> build\lib.win-amd64-2.7\tornado\test
036copying tornado\test\curl_httpclient_test.py -> build\lib.win-amd64-2.7\tornado\
037test
038copying tornado\test\escape_test.py -> build\lib.win-amd64-2.7\tornado\test
039copying tornado\test\gen_test.py -> build\lib.win-amd64-2.7\tornado\test
040copying tornado\test\httpclient_test.py -> build\lib.win-amd64-2.7\tornado\test
041copying tornado\test\httpserver_test.py -> build\lib.win-amd64-2.7\tornado\test
042copying tornado\test\httputil_test.py -> build\lib.win-amd64-2.7\tornado\test
043copying tornado\test\import_test.py -> build\lib.win-amd64-2.7\tornado\test
044copying tornado\test\ioloop_test.py -> build\lib.win-amd64-2.7\tornado\test
045copying tornado\test\iostream_test.py -> build\lib.win-amd64-2.7\tornado\test
046copying tornado\test\locale_test.py -> build\lib.win-amd64-2.7\tornado\test
047copying tornado\test\log_test.py -> build\lib.win-amd64-2.7\tornado\test
048copying tornado\test\netutil_test.py -> build\lib.win-amd64-2.7\tornado\test
049copying tornado\test\options_test.py -> build\lib.win-amd64-2.7\tornado\test
050copying tornado\test\process_test.py -> build\lib.win-amd64-2.7\tornado\test
051copying tornado\test\resolve_test_helper.py -> build\lib.win-amd64-2.7\tornado\t
052est
053copying tornado\test\runtests.py -> build\lib.win-amd64-2.7\tornado\test
054copying tornado\test\simple_httpclient_test.py -> build\lib.win-amd64-2.7\tornad
055o\test
056copying tornado\test\stack_context_test.py -> build\lib.win-amd64-2.7\tornado\te
057st
058copying tornado\test\template_test.py -> build\lib.win-amd64-2.7\tornado\test
059copying tornado\test\testing_test.py -> build\lib.win-amd64-2.7\tornado\test
060copying tornado\test\twisted_test.py -> build\lib.win-amd64-2.7\tornado\test
061copying tornado\test\util.py -> build\lib.win-amd64-2.7\tornado\test
062copying tornado\test\util_test.py -> build\lib.win-amd64-2.7\tornado\test
063copying tornado\test\websocket_test.py -> build\lib.win-amd64-2.7\tornado\test
064copying tornado\test\web_test.py -> build\lib.win-amd64-2.7\tornado\test
065copying tornado\test\wsgi_test.py -> build\lib.win-amd64-2.7\tornado\test
066copying tornado\test\__init__.py -> build\lib.win-amd64-2.7\tornado\test
067creating build\lib.win-amd64-2.7\tornado\platform
068copying tornado\platform\asyncio.py -> build\lib.win-amd64-2.7\tornado\platform
069copying tornado\platform\auto.py -> build\lib.win-amd64-2.7\tornado\platform
070copying tornado\platform\caresresolver.py -> build\lib.win-amd64-2.7\tornado\pla
071tform
072copying tornado\platform\common.py -> build\lib.win-amd64-2.7\tornado\platform
073copying tornado\platform\epoll.py -> build\lib.win-amd64-2.7\tornado\platform
074copying tornado\platform\interface.py -> build\lib.win-amd64-2.7\tornado\platfor
075m
076copying tornado\platform\kqueue.py -> build\lib.win-amd64-2.7\tornado\platform
077copying tornado\platform\posix.py -> build\lib.win-amd64-2.7\tornado\platform
078copying tornado\platform\select.py -> build\lib.win-amd64-2.7\tornado\platform
079copying tornado\platform\twisted.py -> build\lib.win-amd64-2.7\tornado\platform
080copying tornado\platform\windows.py -> build\lib.win-amd64-2.7\tornado\platform
081copying tornado\platform\__init__.py -> build\lib.win-amd64-2.7\tornado\platform
082 
083copying tornado\ca-certificates.crt -> build\lib.win-amd64-2.7\tornado
084copying tornado\test\README -> build\lib.win-amd64-2.7\tornado\test
085creating build\lib.win-amd64-2.7\tornado\test\csv_translations
086copying tornado\test\csv_translations\fr_FR.csv -> build\lib.win-amd64-2.7\torna
087do\test\csv_translations
088creating build\lib.win-amd64-2.7\tornado\test\gettext_translations
089creating build\lib.win-amd64-2.7\tornado\test\gettext_translations\fr_FR
090creating build\lib.win-amd64-2.7\tornado\test\gettext_translations\fr_FR\LC_MESS
091AGES
092copying tornado\test\gettext_translations\fr_FR\LC_MESSAGES\tornado_test.mo -> b
093uild\lib.win-amd64-2.7\tornado\test\gettext_translations\fr_FR\LC_MESSAGES
094copying tornado\test\gettext_translations\fr_FR\LC_MESSAGES\tornado_test.po -> b
095uild\lib.win-amd64-2.7\tornado\test\gettext_translations\fr_FR\LC_MESSAGES
096copying tornado\test\options_test.cfg -> build\lib.win-amd64-2.7\tornado\test
097creating build\lib.win-amd64-2.7\tornado\test\static
098copying tornado\test\static\robots.txt -> build\lib.win-amd64-2.7\tornado\test\s
099tatic
100creating build\lib.win-amd64-2.7\tornado\test\static\dir
101copying tornado\test\static\dir\index.html -> build\lib.win-amd64-2.7\tornado\te
102st\static\dir
103creating build\lib.win-amd64-2.7\tornado\test\templates
104copying tornado\test\templates\utf8.html -> build\lib.win-amd64-2.7\tornado\test
105\templates
106copying tornado\test\test.crt -> build\lib.win-amd64-2.7\tornado\test
107copying tornado\test\test.key -> build\lib.win-amd64-2.7\tornado\test
108running build_ext
109building 'tornado.speedups' extension
110Unable to find vcvarsall.bat
111setup.py:104: UserWarning:
112********************************************************************
113WARNING: The tornado.speedups extension module could not
114be compiled. No C extensions are essential for Tornado to run,
115although they do result in significant speed improvements for
116websockets.
117The output above this warning shows how the compilation failed.
118 
119Here are some hints for popular operating systems:
120 
121If you are seeing this message on Linux you probably need to
122install GCC and/or the Python development package for your
123version of Python.
124 
125Debian and Ubuntu users should issue the following command:
126 
127    $ sudo apt-get install build-essential python-dev
128 
129RedHat, CentOS, and Fedora users should issue the following command:
130 
131    $ sudo yum install gcc python-devel
132 
133If you are seeing this message on OSX please read the documentation
134here:
135 
136http://api.mongodb.org/python/current/installation.html#osx
137********************************************************************
138 
139  "The output above "
140 
141D:\workspace\tornado-3.2.1\tornado-3.2.1>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值