Python 使用mingw构建第三方库 Unable to find vcvarsall.bat错误解决方法
注意:这里使用的mingw32位版本,如果你的电脑上安装的python amd64位版本,那么请使用mingw64位版本,这个很重要,如果版本不正确,那么会报如下错误。
1 | collect2.exe: 错误:ld 返回 1 |
2 | error: 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是否可用
通过以上成功安装mingw
那么如何通过mingw构建项目呢
很简单通过如下命令即可
1 | python setup.py build --compiler=mingw32 |
对就是以上命令这么简单。
以下是如果找不到C编译器得到的错误参考(以Tornado库为例)
001 | D:\workspace\tornado-3.2.1\tornado-3.2.1>python setup.py build |
005 | creating build\lib.win-amd64-2.7 |
006 | creating build\lib.win-amd64-2.7\tornado |
007 | copying tornado\auth.py -> build\lib.win-amd64-2.7\tornado |
008 | copying tornado\autoreload.py -> build\lib.win-amd64-2.7\tornado |
009 | copying tornado\concurrent.py -> build\lib.win-amd64-2.7\tornado |
010 | copying tornado\curl_httpclient.py -> build\lib.win-amd64-2.7\tornado |
011 | copying tornado\escape.py -> build\lib.win-amd64-2.7\tornado |
012 | copying tornado\gen.py -> build\lib.win-amd64-2.7\tornado |
013 | copying tornado\httpclient.py -> build\lib.win-amd64-2.7\tornado |
014 | copying tornado\httpserver.py -> build\lib.win-amd64-2.7\tornado |
015 | copying tornado\httputil.py -> build\lib.win-amd64-2.7\tornado |
016 | copying tornado\ioloop.py -> build\lib.win-amd64-2.7\tornado |
017 | copying tornado\iostream.py -> build\lib.win-amd64-2.7\tornado |
018 | copying tornado\locale.py -> build\lib.win-amd64-2.7\tornado |
019 | copying tornado\log.py -> build\lib.win-amd64-2.7\tornado |
020 | copying tornado\netutil.py -> build\lib.win-amd64-2.7\tornado |
021 | copying tornado\options.py -> build\lib.win-amd64-2.7\tornado |
022 | copying tornado\process.py -> build\lib.win-amd64-2.7\tornado |
023 | copying tornado\simple_httpclient.py -> build\lib.win-amd64-2.7\tornado |
024 | copying tornado\stack_context.py -> build\lib.win-amd64-2.7\tornado |
025 | copying tornado\tcpserver.py -> build\lib.win-amd64-2.7\tornado |
026 | copying tornado\template.py -> build\lib.win-amd64-2.7\tornado |
027 | copying tornado\testing.py -> build\lib.win-amd64-2.7\tornado |
028 | copying tornado\util.py -> build\lib.win-amd64-2.7\tornado |
029 | copying tornado\web.py -> build\lib.win-amd64-2.7\tornado |
030 | copying tornado\websocket.py -> build\lib.win-amd64-2.7\tornado |
031 | copying tornado\wsgi.py -> build\lib.win-amd64-2.7\tornado |
032 | copying tornado\__init__.py -> build\lib.win-amd64-2.7\tornado |
033 | creating build\lib.win-amd64-2.7\tornado\ test |
034 | copying tornado\ test \auth_test.py -> build\lib.win-amd64-2.7\tornado\ test |
035 | copying tornado\ test \concurrent_test.py -> build\lib.win-amd64-2.7\tornado\ test |
036 | copying tornado\ test \curl_httpclient_test.py -> build\lib.win-amd64-2.7\tornado\ |
038 | copying tornado\ test \escape_test.py -> build\lib.win-amd64-2.7\tornado\ test |
039 | copying tornado\ test \gen_test.py -> build\lib.win-amd64-2.7\tornado\ test |
040 | copying tornado\ test \httpclient_test.py -> build\lib.win-amd64-2.7\tornado\ test |
041 | copying tornado\ test \httpserver_test.py -> build\lib.win-amd64-2.7\tornado\ test |
042 | copying tornado\ test \httputil_test.py -> build\lib.win-amd64-2.7\tornado\ test |
043 | copying tornado\ test \import_test.py -> build\lib.win-amd64-2.7\tornado\ test |
044 | copying tornado\ test \ioloop_test.py -> build\lib.win-amd64-2.7\tornado\ test |
045 | copying tornado\ test \iostream_test.py -> build\lib.win-amd64-2.7\tornado\ test |
046 | copying tornado\ test \locale_test.py -> build\lib.win-amd64-2.7\tornado\ test |
047 | copying tornado\ test \log_test.py -> build\lib.win-amd64-2.7\tornado\ test |
048 | copying tornado\ test \netutil_test.py -> build\lib.win-amd64-2.7\tornado\ test |
049 | copying tornado\ test \options_test.py -> build\lib.win-amd64-2.7\tornado\ test |
050 | copying tornado\ test \process_test.py -> build\lib.win-amd64-2.7\tornado\ test |
051 | copying tornado\ test \resolve_test_helper.py -> build\lib.win-amd64-2.7\tornado\t |
053 | copying tornado\ test \runtests.py -> build\lib.win-amd64-2.7\tornado\ test |
054 | copying tornado\ test \simple_httpclient_test.py -> build\lib.win-amd64-2.7\tornad |
056 | copying tornado\ test \stack_context_test.py -> build\lib.win-amd64-2.7\tornado\te |
058 | copying tornado\ test \template_test.py -> build\lib.win-amd64-2.7\tornado\ test |
059 | copying tornado\ test \testing_test.py -> build\lib.win-amd64-2.7\tornado\ test |
060 | copying tornado\ test \twisted_test.py -> build\lib.win-amd64-2.7\tornado\ test |
061 | copying tornado\ test \util.py -> build\lib.win-amd64-2.7\tornado\ test |
062 | copying tornado\ test \util_test.py -> build\lib.win-amd64-2.7\tornado\ test |
063 | copying tornado\ test \websocket_test.py -> build\lib.win-amd64-2.7\tornado\ test |
064 | copying tornado\ test \web_test.py -> build\lib.win-amd64-2.7\tornado\ test |
065 | copying tornado\ test \wsgi_test.py -> build\lib.win-amd64-2.7\tornado\ test |
066 | copying tornado\ test \__init__.py -> build\lib.win-amd64-2.7\tornado\ test |
067 | creating build\lib.win-amd64-2.7\tornado\platform |
068 | copying tornado\platform\asyncio.py -> build\lib.win-amd64-2.7\tornado\platform |
069 | copying tornado\platform\auto.py -> build\lib.win-amd64-2.7\tornado\platform |
070 | copying tornado\platform\caresresolver.py -> build\lib.win-amd64-2.7\tornado\pla |
072 | copying tornado\platform\common.py -> build\lib.win-amd64-2.7\tornado\platform |
073 | copying tornado\platform\epoll.py -> build\lib.win-amd64-2.7\tornado\platform |
074 | copying tornado\platform\interface.py -> build\lib.win-amd64-2.7\tornado\platfor |
076 | copying tornado\platform\kqueue.py -> build\lib.win-amd64-2.7\tornado\platform |
077 | copying tornado\platform\posix.py -> build\lib.win-amd64-2.7\tornado\platform |
078 | copying tornado\platform\ select .py -> build\lib.win-amd64-2.7\tornado\platform |
079 | copying tornado\platform\twisted.py -> build\lib.win-amd64-2.7\tornado\platform |
080 | copying tornado\platform\windows.py -> build\lib.win-amd64-2.7\tornado\platform |
081 | copying tornado\platform\__init__.py -> build\lib.win-amd64-2.7\tornado\platform |
083 | copying tornado\ca-certificates.crt -> build\lib.win-amd64-2.7\tornado |
084 | copying tornado\ test \README -> build\lib.win-amd64-2.7\tornado\ test |
085 | creating build\lib.win-amd64-2.7\tornado\ test \csv_translations |
086 | copying tornado\ test \csv_translations\fr_FR.csv -> build\lib.win-amd64-2.7\torna |
087 | do \ test \csv_translations |
088 | creating build\lib.win-amd64-2.7\tornado\ test \gettext_translations |
089 | creating build\lib.win-amd64-2.7\tornado\ test \gettext_translations\fr_FR |
090 | creating build\lib.win-amd64-2.7\tornado\ test \gettext_translations\fr_FR\LC_MESS |
092 | copying tornado\ test \gettext_translations\fr_FR\LC_MESSAGES\tornado_test.mo -> b |
093 | uild\lib.win-amd64-2.7\tornado\ test \gettext_translations\fr_FR\LC_MESSAGES |
094 | copying tornado\ test \gettext_translations\fr_FR\LC_MESSAGES\tornado_test.po -> b |
095 | uild\lib.win-amd64-2.7\tornado\ test \gettext_translations\fr_FR\LC_MESSAGES |
096 | copying tornado\ test \options_test.cfg -> build\lib.win-amd64-2.7\tornado\ test |
097 | creating build\lib.win-amd64-2.7\tornado\ test \static |
098 | copying tornado\ test \static\robots.txt -> build\lib.win-amd64-2.7\tornado\ test \s |
100 | creating build\lib.win-amd64-2.7\tornado\ test \static\ dir |
101 | copying tornado\ test \static\ dir \index.html -> build\lib.win-amd64-2.7\tornado\te |
103 | creating build\lib.win-amd64-2.7\tornado\ test \templates |
104 | copying tornado\ test \templates\utf8.html -> build\lib.win-amd64-2.7\tornado\ test |
106 | copying tornado\ test \ test .crt -> build\lib.win-amd64-2.7\tornado\ test |
107 | copying tornado\ test \ test .key -> build\lib.win-amd64-2.7\tornado\ test |
109 | building 'tornado.speedups' extension |
110 | Unable to find vcvarsall.bat |
111 | setup.py:104: UserWarning: |
112 | ******************************************************************** |
113 | WARNING: The tornado.speedups extension module could not |
114 | be compiled. No C extensions are essential for Tornado to run, |
115 | although they do result in significant speed improvements for |
117 | The output above this warning shows how the compilation failed. |
119 | Here are some hints for popular operating systems: |
121 | If you are seeing this message on Linux you probably need to |
122 | install GCC and/or the Python development package for your |
125 | Debian and Ubuntu users should issue the following command : |
127 | $ sudo apt-get install build-essential python-dev |
129 | RedHat, CentOS, and Fedora users should issue the following command : |
131 | $ sudo yum install gcc python-devel |
133 | If you are seeing this message on OSX please read the documentation |
136 | http://api.mongodb.org/python/current/installation.html |
137 | ******************************************************************** |
141 | D:\workspace\tornado-3.2.1\tornado-3.2.1> |