在Windows上通过pip使用fastmath(gmp或mpir)构建PyCrypto [英] Building PyCrypto with fastmath (gmp or mpir) via pip on Windows

查看:135
本文介绍了在Windows上通过pip使用fastmath(gmp或mpir)构建PyCrypto的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过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.

  1. 安装 Mingw ,包括MSYS和开发工具包.这将为您提供一个相当完整的类似Unix的开发环境.
  2. 确保Mingw二进制文件位于PATH环境变量中.您需要MinGW\binMingGW\msys\1.0\bin.
  3. 在临时目录中下载 MPIR 源.重要的是,不要不要使用2.5.1,因为会破坏构建的错误. 2.5.0很好.
  4. 构建MPIR库.这非常简单:先执行bash configure,再执行make.
  5. HACK#1 (黑客#1)将libmpir.ampir-2.5.0\.libs复制到C:\Python2.7.1\libs.这是必需的,因为distutils损坏了,我找不到将其定向到正确的库位置的方法.
  6. HACK#2 (),编辑C:\Python2.7.1\Lib\distutils\cygwincompiler.py并删除字符串-mno-cygwin的所有出现. PyCrypto 源并将其解压缩到另一个临时目录中.
  7. CPPFLAGS环境变量设置为包含mpir.h的MPIR目录.
  8. HACK 3 编辑setup.py,并在build_extension方法中添加以下行:

  1. Install Mingw, including MSYS and the Development Toolkit. This will give you a fairly complete Unix-like development environment.
  2. Ensure that Mingw binaries are in PATH environment variable. You need MinGW\bin and MingGW\msys\1.0\bin.
  3. 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.
  4. Build the MPIR library. This is fairly straightforward: execute bash configure followed by make.
  5. HACK #1 Copy libmpir.a from mpir-2.5.0\.libs into C:\Python2.7.1\libs. This is necessary because distutils is broken and I could not find a way to direct it to the correct library location.
  6. 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.
  7. Download PyCrypto sources and unpack them in another temporary directory.
  8. Set CPPFLAGS environment variable to the MPIR directory, which contains mpir.h.
  9. HACK 3 Edit setup.py and add the following line in build_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创建安装程序.
  • Execute python setup.py build -c mingw32. You should see no errors.
  • Execute python setup.py test to verify that everything is fine.
  • Execute python setup.py install to copy the files into your local Python repository.
  • Alternatively, run 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屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆