在Win 7 64位上安装py-bcrypt Python

6 投票
7 回答
7183 浏览
提问于 2025-04-16 23:48

我在Windows 7上尝试安装py-bcrypt,使用的是64位的Python。第一次遇到的错误是找不到vcvarsall.bat这个文件。我在网上查了一下,了解到我需要安装mingw。现在安装好了,但又出现了这个:

C:\tools\python_modules\py-bcrypt-0.2>python setup.py build -c mingw32
running build
running build_py
running build_ext
building 'bcrypt._bcrypt' extension
C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -Ic:\Python27\include -Ic:\Python27\PC -c bcrypt/bcrypt_python.c -o b
d\temp.win-amd64-2.7\Release\bcrypt\bcrypt_python.o
bcrypt/bcrypt_python.c:29:26: error: expected declaration specifiers or '...' before 'u_int8_t'
bcrypt/bcrypt_python.c:29:38: error: expected declaration specifiers or '...' before 'u_int16_t'
bcrypt/bcrypt_python.c:29:49: error: expected declaration specifiers or '...' before 'u_int8_t'
bcrypt/bcrypt_python.c: In function 'bcrypt_encode_salt':
bcrypt/bcrypt_python.c:56:2: error: too many arguments to function 'encode_salt'
bcrypt/bcrypt_python.c:29:6: note: declared here
error: command 'gcc' failed with exit status 1

我不知道接下来该怎么做。看来我可能就不使用bcrypt了,换个别的试试。有其他建议吗?

7 个回答

3

我查看了bcrypt的源代码,但没法弄明白你为什么会出现这个错误(现在手头没有Windows系统来测试)。不过从pybcrypt的问题追踪器来看,它似乎在Windows上有其他编译问题,所以这可能不仅仅是你一个人的问题。猜测一下,通过在gcc参数中添加“--std=C99”到extra_compile_args,可能能解决一些错误。

除此之外,还有几个替代方案 -

  • Bcryptor是另一个C扩展的bcrypt实现,可能可以在你的系统上编译成功。

  • Passlib是一个通用的密码哈希库。虽然它依赖于bcryptor/pybcrypt来支持bcrypt,但它内置了对其他一些密码哈希的支持,可能适合你,比如SHA512-CryptPBKDF2-HMAC-SHA512

  • Cryptacular是另一个通用的密码哈希库。在Windows上,它提供了BCrypt和PBKDF2-HMAC-SHA512密码哈希。(我本来想直接链接到这些,但文档不太让我这么做)

7

有一个适用于Windows的py-bcrypt编译版本。你可以访问 https://bitbucket.org/alexandrul/py-bcrypt/downloads 来下载.exe文件并进行安装。

2

我之前也遇到过同样的问题,后来通过这个链接里的补丁解决了:

http://code.google.com/p/py-bcrypt/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Priority%20Milestone%20Owner%20Summary&groupby=&sort=&id=1

补丁文件名是 py-bcrypt_11.patch

我需要手动应用这个补丁。

根据那个讨论帖,问题的根源在于:

根据这个链接的内容 http://groups.google.com/group/mpir-devel/msg/2c2d4cc7ec12adbb(提到在不同的Windows操作系统、cygwin、mingw等下定义的标志),建议使用 _WIN32 而不是 _MSC_VER。再加上把 bzero 改成 memset,这样在 MSVC 和 MingW32 下都能编译通过。

希望这能帮到你!

撰写回答