项目在Windows下构建,某个密码哈希加密模块使用了py-bcrypt,可惜的是官方只提供了C语言源代码,没有现成的Windows二进制包,我还翻阅了《Unofficial Windows Binaries for Python Extension Packages》也没找到现成的包,当然这个对于Linux系统不成问题,按部就班的安装就OK啦,可是Windows下遇到了些麻烦,比如error: Setup script exited with error: Unable to find vcvarsall.bat错误,于是我采用mingw32进行编译,当然如果你的电脑上没有安装mingw32,可以参考下面的步骤,[来源]:
1. 点击这里下载最新版本的MinGW,并安装。
2. 设置PATH环境变量,比如你装在C:\MinGW路径下,你需要在PATH环境变量中添加C:\MinGW\bin路径。
完成上面两步后切换到项目路径,然后运行命令python setup.py install build --compiler=mingw32,本来以为一切顺利,结果偏偏报cc1.exe: error: unrecognized command line option '-mno-cygwin'错误:
running install
running bdist_egg
running egg_info
creating py_bcrypt.egg-info
writing py_bcrypt.egg-info\PKG-INFO
writing top-level names to py_bcrypt.egg-info\top_level.txt
writing dependency_links to py_bcrypt.egg-info\dependency_links.txt
writing manifest file 'py_bcrypt.egg-info\SOURCES.txt'
reading manifest file 'py_bcrypt.egg-info\SOURCES.txt'
writing manifest file 'py_bcrypt.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
creating build
creating build\lib.win-amd64-2.7
creating build\lib.win-amd64-2.7\bcrypt
copying bcrypt\__init__.py -> build\lib.win-amd64-2.7\bcrypt
running build_ext
building 'bcrypt._bcrypt' extension
creating build\temp.win-amd64-2.7
creating build\temp.win-amd64-2.7\Release
creating build\temp.win-amd64-2.7\Release\bcrypt
D:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -ID:\Python27\include -ID:\Pytho
n27\PC -c bcrypt/bcrypt_python.c -o build\temp.win-amd64-2.7\Release\bcrypt\bcry
pt_python.o
cc1.exe: error: unrecognized command line option '-mno-cygwin'
error: command 'gcc' failed with exit status 1
搜索了网络,找到这么篇求助《mingw32编译安装Python第三方库失败,:unrecognized command line option ‘-mno-cygwin’》,得知-mno-cygwin参数已经不被新版本的gcc支持了,所以需要修改源代码移除这个参数:
如果你的Python27装在C盘的,那么可以打开C:\Python27\Lib\distutils\cygwinccompiler.py文件,然后找到大概322行左右下面一段:
322
323
324
325
326
327
328
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 -mno-cygwin',
linker_so='%s -mno-cygwin %s %s'
% (self.linker_dll, shared_option,
entry_point))
删除所有的-mno-cygwin字符串,然后保存。
好了,接下来可以继续了,重复刚才的安装命令,但是我又想错了,编译py-bcrypt出现下面的错误提示:
running install
running bdist_egg
running egg_info
writing py_bcrypt.egg-info\PKG-INFO
writing top-level names to py_bcrypt.egg-info\top_level.txt
writing dependency_links to py_bcrypt.egg-info\dependency_links.txt
reading manifest file 'py_bcrypt.egg-info\SOURCES.txt'
writing manifest file 'py_bcrypt.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
running build_ext
building 'bcrypt._bcrypt' extension
D:\MinGW\bin\gcc.exe -mdll -O -Wall -ID:\Python27\include -ID:\Python27\PC -c bc
rypt/bcrypt_python.c -o build\temp.win-amd64-2.7\Release\bcrypt\bcrypt_python.o
bcrypt/bcrypt_python.c:29:26: error: unknown type name 'u_int8_t'
bcrypt/bcrypt_python.c:29:38: error: unknown type name 'u_int16_t'
bcrypt/bcrypt_python.c:29:49: error: unknown type name 'u_int8_t'
bcrypt/bcrypt_python.c: In function 'bcrypt_encode_salt':
bcrypt/bcrypt_python.c:56:2: warning: implicit declaration of function 'encode_s
alt' [-Wimplicit-function-declaration]
error: command 'gcc' failed with exit status 1
重点是形如unknown type name 'u_int8_t'的错误,Windows SDK环境下没有定义这个类型,最后在stackoverflow的这篇求助《py-bcrypt installing on win 7 64bit python》找到了答案,为了能够在Windows下编译,我们还需要打一个Patch,我们可以到这里下载这个Patch。
问题又来了:Windows下如何打这个Patch呢?幸好我们可以找到Python下的一个实用脚本python-patch,下载后可以重命名为patch.py并保存到C:\Python27\Scripts(假设Python安装在C盘)下,然后运行形如命令C:\Python27\Scripts\patch.py file1.patch来打patch,注意这里的file1.patch是你刚才下载的patch文件。
打好patch后,让我们再次执行刚才的编译安装命令,结果依旧失败:
running install
running bdist_egg
running egg_info
writing py_bcrypt.egg-info\PKG-INFO
writing top-level names to py_bcrypt.egg-info\top_level.txt
writing dependency_links to py_bcrypt.egg-info\dependency_links.txt
reading manifest file 'py_bcrypt.egg-info\SOURCES.txt'
writing manifest file 'py_bcrypt.egg-info\SOURCES.txt'
installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
running build_ext
building 'bcrypt._bcrypt' extension
D:\MinGW\bin\gcc.exe -mdll -O -Wall -ID:\Python27\include -ID:\Python27\PC -c bc
rypt/bcrypt_python.c -o build\temp.win-amd64-2.7\Release\bcrypt\bcrypt_python.o
bcrypt/bcrypt_python.c: In function 'bcrypt_encode_salt':
bcrypt/bcrypt_python.c:56:2: warning: pointer targets in passing argument 2 of '
encode_salt' differ in signedness [-Wpointer-sign]
bcrypt/bcrypt_python.c:29:6: note: expected 'u_int8_t *' but argument is of type
'char *'
D:\MinGW\bin\gcc.exe -mdll -O -Wall -ID:\Python27\include -ID:\Python27\PC -c bc
rypt/blowfish.c -o build\temp.win-amd64-2.7\Release\bcrypt\blowfish.o
D:\MinGW\bin\gcc.exe -mdll -O -Wall -ID:\Python27\include -ID:\Python27\PC -c bc
rypt/bcrypt.c -o build\temp.win-amd64-2.7\Release\bcrypt\bcrypt.o
writing build\temp.win-amd64-2.7\Release\bcrypt\_bcrypt.def
D:\MinGW\bin\gcc.exe -shared -s build\temp.win-amd64-2.7\Release\bcrypt\bcrypt_p
ython.o build\temp.win-amd64-2.7\Release\bcrypt\blowfish.o build\temp.win-amd64-
2.7\Release\bcrypt\bcrypt.o build\temp.win-amd64-2.7\Release\bcrypt\_bcrypt.def
-LD:\Python27\libs -LD:\Python27\PCbuild\amd64 -lpython27 -lmsvcr90 -o build\lib
.win-amd64-2.7\bcrypt\_bcrypt.pyd
build\temp.win-amd64-2.7\Release\bcrypt\bcrypt_python.o:bcrypt_python.c:(.text+0
x5b): undefined reference to `_imp__PyArg_ParseTupleAndKeywords'
build\temp.win-amd64-2.7\Release\bcrypt\bcrypt_python.o:bcrypt_python.c:(.text+0
x73): undefined reference to `_imp__PyExc_ValueError'
build\temp.win-amd64-2.7\Release\bcrypt\bcrypt_python.o:bcrypt_python.c:(.text+0
x7e): undefined reference to `_imp__PyErr_SetString'
build\temp.win-amd64-2.7\Release\bcrypt\bcrypt_python.o:bcrypt_python.c:(.text+0
x9e): undefined reference to `_imp__PyExc_ValueError'
build\temp.win-amd64-2.7\Release\bcrypt\bcrypt_python.o:bcrypt_python.c:(.text+0
xa9): undefined reference to `_imp__PyErr_SetString'
build\temp.win-amd64-2.7\Release\bcrypt\bcrypt_python.o:bcrypt_python.c:(.text+0
xdc): undefined reference to `_imp__PyString_FromString'
build\temp.win-amd64-2.7\Release\bcrypt\bcrypt_python.o:bcrypt_python.c:(.text+0
x134): undefined reference to `_imp__PyArg_ParseTupleAndKeywords'
build\temp.win-amd64-2.7\Release\bcrypt\bcrypt_python.o:bcrypt_python.c:(.text+0
x15e): undefined reference to `_imp__PyEval_SaveThread'
build\temp.win-amd64-2.7\Release\bcrypt\bcrypt_python.o:bcrypt_python.c:(.text+0
x177): undefined reference to `_imp__PyEval_RestoreThread'
build\temp.win-amd64-2.7\Release\bcrypt\bcrypt_python.o:bcrypt_python.c:(.text+0
x1b0): undefined reference to `_imp__PyExc_ValueError'
build\temp.win-amd64-2.7\Release\bcrypt\bcrypt_python.o:bcrypt_python.c:(.text+0
x1bb): undefined reference to `_imp__PyErr_SetString'
build\temp.win-amd64-2.7\Release\bcrypt\bcrypt_python.o:bcrypt_python.c:(.text+0
x1cb): undefined reference to `_imp__PyString_FromString'
build\temp.win-amd64-2.7\Release\bcrypt\bcrypt_python.o:bcrypt_python.c:(.text+0
x20a): undefined reference to `_imp__Py_InitModule4'
build\temp.win-amd64-2.7\Release\bcrypt\bcrypt_python.o:bcrypt_python.c:(.text+0
x223): undefined reference to `_imp__PyModule_AddStringConstant'
collect2: ld returned 1 exit status
error: command 'gcc' failed with exit status 1
这次出现大量的undefined reference to错误,搜索网络,然后设置C:\Python27\libs到环境变量中,错误依旧,然后我就怀疑是否和我的64位Windows 7和64位Python 27有关系了,结果还真是这个原因,最后还是使用微软的MSVC编译成功的,关于详细步骤可以参考下一篇文章。
分享到:
相关推荐
解决 error: Unable to find vcvarsall.bat 配置文件。 安装vs后,根据vs版本修改VS90COMNTOOLS对应的数字(我安装的是vs2013),安装了vs2013,测试不同的机子上使用配置文件解决问题
当你试图编译Python扩展模块,如Cython,或者使用其他需要MSVC(Microsoft Visual C++)编译器的项目时,可能会遇到“error: Unable to find vcvarsall.bat”的错误。这个错误通常意味着系统无法找到必要的编译环境...
在windows下使用pip安装一些python的第三方库,有很多使用C写了一些扩展,需要使用VC++ Compiler 来编译安装(也可使用MInGW,一般不推荐),否则就会出现“Unable to find vcvarsall.bat”。像Python2.7就需要...
### Python安装PIL模块时Unable to find vcvarsall.bat错误的解决方法 #### 错误概述 在Python环境中安装PIL(Python Imaging Library)模块时,可能会遇到“Unable to find vcvarsall.bat”这一错误提示。该问题...
1、解决Windows下安装FastDFS报 Microsoft Visual C++ 9.0 is required Unable to find vcvarsall.bat 问题 2、解决Windows下安装FastDFS报 fdfs_client/sendfilemodule.c(53) fatal error C1189: #error : platfom ...
Python安装支持库的过程中经常会遇到“Microsoft Visual C++ 14.0 is required”或者“unable to find vcvarsall.bat”的问题,此时就需要安装Visual C++ build tools生成工具,下载链接。但该安装包为在线安装包,...
Python安装支持库的过程中经常会遇到“Microsoft Visual C++ 14.0 is required”或者“unable to find vcvarsall.bat”的问题,此时就需要安装Visual C++ build tools生成工具,下载链接。但该安装包为在线安装包,...
如果遇到错误:ImportError: DLL load failed: 找不到指定的模块 Microsoft Visual C++ 9.0 is required Unable to find vcvarsall.bat 需要通过pip uninstall卸载,再去到python的Scripts文件夹下安装whl文件,...
python 安装gevent1. 问题在python2.7中安装gevent的时候出现 error: Unable to find vcvarsall.bat
特别是当遇到"Microsoft Visual C++ 14.0 is required"或"unable to find vcvarsall.bat"这类错误提示时,这表明系统缺少Visual C++ Build Tools。本文将详细介绍如何通过离线方式下载并安装Visual C++ Build Tools ...
有效解决安装mysql-python时遇到的error: Unable to find vcvarsall.bat问题,哎,安装mingw什么的,都是浮云啊(搞了一上午都没有成功啊)!还是这个有用!
通过pip3 install Scrapy直接安装,一般会报错:error: Unable to find vcvarsall.bat 网上的解决办法有2种: 通过wheel来安装lxml.whl、twisted.whl 安装vs2015,并勾选各种支持python的选项 这里果断选择了方法...
1、python 3.7 使用 Cython 转 .py 到 .pyd 文件 出错 error: Unable to find vcvarsall.bat 2、安装资料上传的两个文件即可 3、安装时记得勾选C++ 选项
如果在安装过程中遇到 "unable to find vcvarsall.bat" 错误,可以查看相关解决方案(http://www.biaodianfu.com/python-error-unable-to-find-vcvarsall-bat.html)。 安装 Python 2.7.10 及其相关库 numpy、scipy...
如果无此安装并没有相对高版本的Visio Studio的安装,会有最终错误“DistutilsPlatformError: Unable to find vcvarsall.bat”。 使用方法 装完了上述Visual c++ Build Tools之后,一般不用按某些网页说的要改某.py...
在安装pyhton扩展时,会报错:unable to find vcvarsall.bat。 是因为扩展使用C/C++编写,缺少编译需要的环境,而python2.x和3.x使用的版本也不一样,此资源提供了两个都需要的,可以根据自己的python版本选择使用。
1、python编译扩展时,error: Unable to find vcvarsall.bat,缺少c++编译工具 2、在windows下开发应用或库时,如果不想安装完整的visual studio,可以选择只安装build tools在命令行下进行编译等操作
python3.5 32位 mysqlclient,主要解决window系统,未安装VC工具情况下,报错“error: Unable to find vcvarsall.bat”,安装python扩展使用。