在Windows上通过pip使用fastmath(gmp或mpir)构建PyCrypto [英] Building PyCrypto with fastmath (gmp or mpir) via pip on Windows
问题描述
我通过pip在Windows上安装了PyCrypto,但是由于找不到GMP,所以我无法构建Crypto.PublicKey._fastmath.
I installed PyCrypto on Windows via pip but i was not able to build Crypto.PublicKey._fastmath because GMP was not found.
我知道无效空间上有二进制版本,但我会喜欢构建最新版本的PyCrypto
I know there is a binary version on voidspace but i would like to build the latest version of PyCrypto
推荐答案
以下是实现目标的一种方法.还有其他可能更好的方法(例如基于Visual Studio),但是这种方法对我有用.此外,它不使用pip
.
The following one is a way to achieve your goal. There are other, probably better ways (e.g. based on Visual Studio), but this one has worked for me. Additionally, it does not use pip
.
所有操作都在命令提示符下进行.
All operations are carried out on a command prompt.
- 安装 Mingw ,包括MSYS和开发工具包.这将为您提供一个相当完整的类似Unix的开发环境.
- 确保Mingw二进制文件位于PATH环境变量中.您需要
MinGW\bin
和MingGW\msys\1.0\bin
. - 在临时目录中下载 MPIR 源.重要的是,不要不要使用2.5.1,因为会破坏构建的错误. 2.5.0很好.
- 构建MPIR库.这非常简单:先执行
bash configure
,再执行make
. - HACK#1 (黑客#1)将
libmpir.a
从mpir-2.5.0\.libs
复制到C:\Python2.7.1\libs
.这是必需的,因为distutils
损坏了,我找不到将其定向到正确的库位置的方法. - HACK#2 (
),编辑 C:\Python2.7.1\Lib\distutils\cygwincompiler.py
并删除字符串-mno-cygwin
的所有出现. PyCrypto 源并将其解压缩到另一个临时目录中. - 将
CPPFLAGS
环境变量设置为包含mpir.h
的MPIR目录. -
HACK 3 编辑
setup.py
,并在build_extension
方法中添加以下行:
- Install Mingw, including MSYS and the Development Toolkit. This will give you a fairly complete Unix-like development environment.
- Ensure that Mingw binaries are in PATH environment variable. You need
MinGW\bin
andMingGW\msys\1.0\bin
. - Download MPIR sources in a temporary directory. It is important you do not use 2.5.1 because of a bug that will break the build. 2.5.0 is fine.
- Build the MPIR library. This is fairly straightforward: execute
bash configure
followed bymake
. - HACK #1 Copy
libmpir.a
frommpir-2.5.0\.libs
intoC:\Python2.7.1\libs
. This is necessary becausedistutils
is broken and I could not find a way to direct it to the correct library location. - HACK #2 Edit
C:\Python2.7.1\Lib\distutils\cygwincompiler.py
and remove any occurrance of the string-mno-cygwin
. The reason is explained here. - Download PyCrypto sources and unpack them in another temporary directory.
- Set
CPPFLAGS
environment variable to the MPIR directory, which containsmpir.h
. HACK 3 Edit
setup.py
and add the following line inbuild_extension
method:
self .__ add_compiler_option(os.environ ['CPPFLAGS'])
self.__add_compiler_option(os.environ['CPPFLAGS'])
运行bash configure
.您应该看到两行内容:
Run bash configure
. You should see two lines saying:
正在-lgmp中检查__gmpz_init ...否
检查-lmpir中的__gmpz_init ...是
checking for __gmpz_init in -lgmp... no
checking for __gmpz_init in -lmpir... yes
python setup.py build -c mingw32
.您应该不会看到任何错误.python setup.py test
以确认一切正常.python setup.py install
将文件复制到本地Python存储库中.python setup.py bdist_wininst
创建安装程序.
python setup.py build -c mingw32
. You should see no errors.python setup.py test
to verify that everything is fine.python setup.py install
to copy the files into your local Python repository.python setup.py bdist_wininst
to create an installer.我真的很讨厌所有各种各样的骇客,我很想听听它们是否可以避免.
I really hate all the various hacks, and I'd love to hear if they can be avoided.
这篇关于在Windows上通过pip使用fastmath(gmp或mpir)构建PyCrypto的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!