问题:如何在Windows上安装PyCrypto?

我已经阅读了所有其他Google来源和SO线程,但没有任何效果。

Python 2.7.3 32bit安装在上Windows 7 64bit。下载,解压缩然后尝试在以下位置安装PyCrypto结果"Unable to find vcvarsall.bat".

因此,我安装了MinGW,并将其作为选择的编译器安装在安装线上。但是然后我得到了错误"RuntimeError: chmod error".

我该如何解决这个问题?我试过使用pip,它给出相同的结果。我找到了一个预构建的PyCrypto 2.3二进制文件并进行了安装,但是在系统上找不到该文件(无法正常工作)。

有任何想法吗?

I’ve read every other google source and SO thread, with nothing working.

Python 2.7.3 32bit installed on Windows 7 64bit. Download, extracting, and then trying to install PyCrypto results in "Unable to find vcvarsall.bat".

So I install MinGW and tack that on the install line as the compiler of choice. But then I get the error "RuntimeError: chmod error".

How in the world do I get around this? I’ve tried using pip, which gives the same result. I found a prebuilt PyCrypto 2.3 binary and installed that, but it’s nowhere to be found on the system (not working).

Any ideas?


回答 0

如果尚未安装与Python.org分发的Visual Studio二进制文件兼容的C / C ++开发环境,则应坚持仅安装纯Python软件包或可用于Windows二进制文件的软件包。

幸运的是,有适用于Windows的PyCrypto二进制文件:http ://www.voidspace.org.uk/python/modules.shtml#pycrypto

更新:
正如@Udi在下面的注释中建议的那样,以下命令也将安装pycrypto并可以在其中使用virtualenv

easy_install http://www.voidspace.org.uk/python/pycrypto-2.6.1/pycrypto-2.6.1.win32-py2.7.exe

注意,请从此列表中选择与您的设置相关的链接

如果您正在寻找适用于Python 3.5的版本,请参阅python 3.5上的PyCrypto

If you don’t already have a C/C++ development environment installed that is compatible with the Visual Studio binaries distributed by Python.org, then you should stick to installing only pure Python packages or packages for which a Windows binary is available.

Fortunately, there are PyCrypto binaries available for Windows: http://www.voidspace.org.uk/python/modules.shtml#pycrypto

UPDATE:
As @Udi suggests in the comment below, the following command also installs pycrypto and can be used in virtualenv as well:

easy_install http://www.voidspace.org.uk/python/pycrypto-2.6.1/pycrypto-2.6.1.win32-py2.7.exe

Notice to choose the relevant link for your setup from this list

If you’re looking for builds for Python 3.5, see PyCrypto on python 3.5


回答 1

Microsoft最近最近发布了用于Python 2.7的独立的专用Microsoft Visual C ++编译器。如果您使用的是Python 2.7,只需安装该编译器和Setuptools 6.0或更高版本,大多数具有C扩展名的软件包现在都可以轻松编译。

Microsoft has recently recently released a standalone, dedicated Microsoft Visual C++ Compiler for Python 2.7. If you’re using Python 2.7, simply install that compiler and Setuptools 6.0 or later, and most packages with C extensions will now compile readily.


回答 2

经过数年之久,python终于同意了一种二进制发行版wheel,该发行版允许在Windows上安装甚至二进制扩展,而无需使用简单的编译器pip install packagename。有一种流行的软件包列表及其状态。Pycrypto还不存在,例如lxml,PySide和Scrapy。

2015年11月编辑pip uninstall pycryptopip install pycryptodome。这是pycrypto具有新功能的前叉,并且支持车轮。它取代了pycrypto,因此现有代码将继续起作用(请参阅https://pycryptodome.readthedocs.org/en/latest/src/examples.html

After years and years, python finally agreed for a binary disribution called wheel which allows to install even binary extensions on Windows without having a compiler with simple pip install packagename. There is a list of popular packages with their status. Pycrypto is not there yet, but lxml, PySide and Scrapy for example.

Edited Nov 2015: pip uninstall pycrypto & pip install pycryptodome. It is a pycrypto fork with new features and it supports wheel. It replaces pycrypto, so existing code will continue to work (see https://pycryptodome.readthedocs.org/en/latest/src/examples.html)


回答 3

对于VS2010:

SET VS90COMNTOOLS=%VS100COMNTOOLS%

对于VS2012:

SET VS90COMNTOOLS=%VS110COMNTOOLS%

然后调用:

pip install pyCrypto 

For VS2010:

SET VS90COMNTOOLS=%VS100COMNTOOLS%

For VS2012:

SET VS90COMNTOOLS=%VS110COMNTOOLS%

then Call:

pip install pyCrypto 

回答 4

一般来说

vcvarsall.bat是Visual C ++编译器的一部分,您需要安装要安装的内容。如果您的Python是使用Visual Studio工具链编译的,甚至不要尝试处理MingGW,反之亦然。甚至Microsoft工具链的版本也很重要。用VS 2008编译的Python不能与用VS 2010编译的扩展一起使用!

您必须使用与Python版本相同的编译器来编译PyCrypto。Google的“无法找到vcvarsall.bat”,因为这是问题的根源,这是在Windows上编译Python扩展的一个非常普遍的问题。

在使用此链接的任何系统上,要获得正确的信息,都需要大量的信息和大量的阅读。

注意使用Visual Studio 2010或不使用Visual Studio 2008

据我所知,以下仍然是正确的。这是在2010年6月的链接中发布的,该链接是指尝试针对python.org上可用的Python安装程序使用VS 2010 Express构建扩展。

如果这样做,请小心。python.org的Python 2.6和2.7是使用Visual Studio 2008编译器构建的。您将需要使用与Python相同的CRT(msvcr90.dll)进行链接。

Visual Studio 2010 Express链接到错误的CRT版本:msvcr100.dll。

如果执行此操作,则还必须使用Visual Studio 2010 Express重新构建Python。您不能将标准的Python二进制安装程序用于Windows。您也不能使用使用与Visual Studio 2010(Express)不同的编译器构建的任何C / C ++扩展。

意见:这是我放弃Windows从事OSX的所有重要开发工作的原因之一!

In general

vcvarsall.bat is part of the Visual C++ compiler, you need that to install what you are trying to install. Don’t even try to deal with MingGW if your Python was compiled with Visual Studio toolchain and vice versa. Even the version of the Microsoft tool chain is important. Python compiled with VS 2008 won’t work with extensions compiled with VS 2010!

You have to compile PyCrypto with the same compiler that the version of Python was compiled with. Google for “Unable to find vcvarsall.bat” because that is the root of your problem, it is a very common problem with compiling Python extensions on Windows.

There is a lot of information and a lot to read to get this right on whatever system you are on with this link.

Beware using Visual Studio 2010 or not using Visual Studio 2008

As far as I know the following is still true. This was posted in the link above in June, 2010 referring to trying to build extensions with VS 2010 Express against the Python installers available on python.org.

Be careful if you do this. Python 2.6 and 2.7 from python.org are built with Visual Studio 2008 compilers. You will need to link with the same CRT (msvcr90.dll) as Python.

Visual Studio 2010 Express links with the wrong CRT version: msvcr100.dll.

If you do this, you must also re-build Python with Visual Studio 2010 Express. You cannot use the standard Python binary installer for Windows. Nor can you use any C/C++ extensions built with a different compiler than Visual Studio 2010 (Express).

Opinion: This is one reason I abandoned Windows for all serious development work for OSX!


回答 5

PyCryptodomePyCrypto的几乎兼容的分支,带有pypi上的Windows轮子。

您可以使用以下简单的方法安装它:

pip install pycryptodome

该网站还包含使用Microsoft编译器从源进行构建的说明。

PyCryptodome is an almost-compatible fork of PyCrypto with Windows wheels available on pypi.

You can install it with a simple:

pip install pycryptodome

The website includes instructions to build it from sources with the Microsoft compilers too.


回答 6

我设法pycrypto通过使用MinGW32和进行编译MSYS。假定您已安装pipeasy_install安装。

这是我的做法:

1)安装MinGW32。为了便于说明,我们假设它已安装在中C:\MinGW。我建议使用安装程序时,选择. MSYS应该随其一起安装的C ++编译器MinGW

2)添加c:\mingw\bin,c:\mingw\mingw32\bin,C:\MinGW\msys\1.0, c:\mingw\msys\1.0\bin and c:\mingw\msys\1.0\sbin到您的中%PATH%。如果您不熟悉,这篇文章会很有帮助。

3)从搜索栏中运行msys,然后MSYS终端将打开。对于熟悉的人Cygwin,它的工作方式类似。

4)pip install pycrypto在此之后,应从MSYS终端内部正常运行。

I have managed to get pycrypto to compile by using MinGW32 and MSYS. This presumes that you have pip or easy_install installed.

Here’s how I did it:

1) Install MinGW32. For the sake of this explanation, let’s assume it’s installed in C:\MinGW. When using the installer, which I recommend, select the C++ compiler. MSYS should install with MinGW

2) Add c:\mingw\bin,c:\mingw\mingw32\bin,C:\MinGW\msys\1.0, c:\mingw\msys\1.0\bin and c:\mingw\msys\1.0\sbin to your %PATH%. If you aren’t familiar, this article is very helpful.

3) From the search bar, run msys and the MSYS terminal will open. For those familiar with Cygwin, it works in a similar fashion.

4) From within the MSYS terminal pip install pycrypto should run without error after this.


回答 7

对于Windows 7:

要在Windows中安装Pycrypto,

在命令提示符中尝试此操作,

设置路径= C:\ Python27 \ Scripts(即easy_install所在的路径)

然后执行以下命令

easy_install pycrypto

对于Ubuntu:

试试这个,

从“ https://pypi.python.org/pypi/pycrypto ” 下载Pycrypto

然后使用终端将当前路径更改为下载路径,并且用户应为root:

例如:root @ xyz-virtual-machine:〜/ pycrypto-2.6.1#

然后使用终端执行以下命令:

python setup.py安装

对我有用。希望为所有人服务。

For Windows 7:

To install Pycrypto in Windows,

Try this in Command Prompt,

Set path=C:\Python27\Scripts (i.e path where easy_install is located)

Then execute the following,

easy_install pycrypto

For Ubuntu:

Try this,

Download Pycrypto from “https://pypi.python.org/pypi/pycrypto

Then change your current path to downloaded path using your terminal and user should be root:

Eg: root@xyz-virtual-machine:~/pycrypto-2.6.1#

Then execute the following using the terminal:

python setup.py install

It’s worked for me. Hope works for all..


回答 8

对于那些正在寻找python 3.4的人,我发现了一个可以正常使用的安装程序的git repo。这是x64的直接链接x32

For those of you looking for python 3.4 I found a git repo with an installer that just works. Here are the direct links for x64 and x32


回答 9

可以使用Windows 7 SDK工具包构建PyCrypto。Windows 7 SDK有两个版本。原始版本(针对.Net 3.5)包括VS 2008命令行编译器。可以同时安装32位和64位编译器。

第一步是编译mpir以提供快速算法。我已经记录了在gmpy库中使用的过程。可以在sdk_build中找到使用SDK编译器构建mpir的详细说明。

在DOS提示符下使用SDK编译器的关键步骤是:

1)根据需要运行vcvars32.bat或vcvars64.bat。

2)在提示符下,执行“ set MSSdk = 1”

3)在提示符下,执行“ set DISTUTILS_USE_SDK = 1”

假设C代码没有其他问题,这应该可以使“ python setup.py install”成功。但是我模糊地记得我不得不编辑几个PyCrypto文件来启用mpir并找到mpir库,但是目前我没有Windows系统。我将需要几天的时间来重新创建这些步骤。如果您到那时还没有报告成功,我将发布PyCrypto步骤。这些步骤将假定您能够编译mpir。

我希望这有帮助。

It’s possible to build PyCrypto using the Windows 7 SDK toolkits. There are two versions of the Windows 7 SDK. The original version (for .Net 3.5) includes the VS 2008 command-line compilers. Both 32- and 64-bit compilers can be installed.

The first step is to compile mpir to provide fast arithmetic. I’ve documented the process I use in the gmpy library. Detailed instructions for building mpir using the SDK compiler can be found at sdk_build

The key steps to use the SDK compilers from a DOS prompt are:

1) Run either vcvars32.bat or vcvars64.bat as appropriate.

2) At the prompt, execute “set MSSdk=1”

3) At the prompt, execute “set DISTUTILS_USE_SDK=1”

This should allow “python setup.py install” to succeed assuming there are no other issues with the C code. But I vaaguely remember that I had to edit a couple of PyCrypto files to enable mpir and to find the mpir libraries but I don’t have my Windows system up at the moment. It will be a couple of days before I’ll have time to recreate the steps. If you haven’t reported success by then, I’ll post the PyCrypto steps. The steps will assume you were able to compile mpir.

I hope this helps.


回答 10

尝试仅使用:

pip install pycryptodome

要么:

pip install pycryptodomex

来源:https : //pypi.python.org/pypi/pycryptodome

Try just using:

pip install pycryptodome

or:

pip install pycryptodomex

Source: https://pypi.python.org/pypi/pycryptodome


回答 11

因此,我安装了MinGW,并将其作为选择的编译器安装在安装线上。但是,然后我得到错误“ RuntimeError:chmod错误”。

"RuntimeError: chmod error"发生此错误是因为安装脚本找不到chmod命令。

我该如何解决这个问题?

您只需要将MSYS二进制文件添加到PATH并重新运行安装脚本即可

(注意:MinGW随MSYS一起提供)

例如,如果我们在文件夹中 C:\<..>\pycrypto-2.6.1\dist\pycrypto-2.6.1>

C:\.....>set PATH=C:\MinGW\msys\1.0\bin;%PATH%
C:\.....>python setup.py install

可选:在重新运行脚本之前,您可能需要清理:

`C:\<..>\pycrypto-2.6.1\dist\pycrypto-2.6.1> python setup.py clean`

So I install MinGW and tack that on the install line as the compiler of choice. But then I get the error “RuntimeError: chmod error”.

This error "RuntimeError: chmod error" occurs because the install script didn’t find the chmod command.

How in the world do I get around this?

Solution

You only need to add the MSYS binaries to the PATH and re-run the install script.

(N.B: Note that MinGW comes with MSYS so )

Example

For example, if we are in folder C:\<..>\pycrypto-2.6.1\dist\pycrypto-2.6.1>

C:\.....>set PATH=C:\MinGW\msys\1.0\bin;%PATH%
C:\.....>python setup.py install

Optional: you might need to clean before you re-run the script:

`C:\<..>\pycrypto-2.6.1\dist\pycrypto-2.6.1> python setup.py clean`

回答 12

  1. 转到适用于Python 2.7的Microsoft Visual C ++编译器 ”,然后根据“系统要求”继续操作(这是我按照以下步骤进行的工作)。

  2. 安装setuptools(6.0或更高版本需要Python来自动检测setuptools的这个编译器包) 或者通过: pip install setuptools 下载“setuptools的自举安装”源来自于你的filestystem为“ez_python.py”,保存这个文件somwhere与安装:python ez_python.py

  3. 安装滚轮(建议使用滚轮来生产预构建的二进制软件包)。您可以使用以下方法安装它:pip install wheel

  4. 打开Windows提升的命令提示符cmd.exe(带有“以管理员身份运行”),为所有用户安装“适用于Python 2.7的Microsoft Visual C ++编译器”。您可以使用以下命令来执行此操作:msiexec / i C:\users\jozko\download\VCForPython27.msi ALLUSERS=1仅使用您自己的文件路径:msiexec /i <path to MSI> ALLUSERS=1

  5. 现在,您应该能够使用以下命令安装pycrypto: pip install pycrypto

  1. Go to Microsoft Visual C++ Compiler for Python 2.7 and continue based on “System Requirements” (this is what I did to put below steps together).

  2. Install setuptools (setuptools 6.0 or later is required for Python to automatically detect this compiler package) either by: pip install setuptools or download “Setuptools bootstrapping installer” source from, save this file somwhere on your filestystem as “ez_python.py” and install with: python ez_python.py

  3. Install wheel (wheel is recommended for producing pre-built binary packages). You can install it with: pip install wheel

  4. Open Windows elevated Command Prompt cmd.exe (with “Run as administrator”) to install “Microsoft Visual C++ Compiler for Python 2.7” for all users. You can use following command to do so: msiexec /i C:\users\jozko\download\VCForPython27.msi ALLUSERS=1 just use your own path to file: msiexec /i <path to MSI> ALLUSERS=1

  5. Now you should be able to install pycrypto with: pip install pycrypto


回答 13

如果您在Windows上并且正在努力安装Pycrypcto,请使用:pip install pycryptodome。它像奇迹一样运作,比起进行大量的配置和调整将使您的生活更加轻松。

If you are on Windows and struggling with installing Pycrypcto just use the: pip install pycryptodome. It works like a miracle and it will make your life much easier than trying to do a lot of configurations and tweaks.


回答 14

这可能不是最佳解决方案,但是您可以从MS下载并安装免费的Visual C ++ Express软件包。这将为您提供编译PyCrypto代码所需的C ++编译器。

This probably isn’t the optimal solution but you might download and install the free Visual C++ Express package from MS. This will give you the C++ compiler you need to compile the PyCrypto code.


回答 15

我的答案可能与此处提到的问题无关,但是我对Python 3.4遇到了同样的问题,其中Crypto.Cipher不是有效的导入。所以我尝试安装PyCrypto并遇到问题。

经过研究,我发现3.4应该使用pycryptodome

我使用pycharm安装pycryptodome,效果很好。

Crypto.Cipher导入AES

My answer might not be related to problem mention here, but I had same problem with Python 3.4 where Crypto.Cipher wasn’t a valid import. So I tried installing PyCrypto and went into problems.

After some research I found with 3.4 you should use pycryptodome.

I install pycryptodome using pycharm and I was good.

from Crypto.Cipher import AES


回答 16

因此,我安装了MinGW,并将其作为选择的编译器安装在安装线上。但是,然后我得到错误“ RuntimeError:chmod错误”。

您需要在MinGW下安装msys软件包

在此处输入图片说明

并在PATH env变量中添加以下条目。

  • C:\MinGW\bin
  • C:\MinGW\msys\1.0\bin [在这里您将找到chmod可执行文件]

然后从正常的Windows命令提示符下运行命令。

So I install MinGW and tack that on the install line as the compiler of choice. But then I get the error “RuntimeError: chmod error”.

You need to install msys package under MinGW

enter image description here

and add following entries in your PATH env variable.

  • C:\MinGW\bin
  • C:\MinGW\msys\1.0\bin [This is where you will find chmod executable]

Then run your command from normal windows command prompt.


回答 17

由于奇怪的法律原因,二进制文件无法正常发布。空隙空间通常是最好的第二个来源。但是由于相当长的一段时间,voidspace维护程序没有更新。使用[ https://www.dropbox.com/s/n6rckn0k6u4nqke/pycrypto-2.6.1.zip?dl=0]中的压缩文件

Due to weird legal reasons, binaries are not published the normal way. Voidspace is normally the best second source. But since quite some time, voidspace maintainer did not update. Use the zip from [https://www.dropbox.com/s/n6rckn0k6u4nqke/pycrypto-2.6.1.zip?dl=0]


回答 18

步骤1:从此处安装Visual C ++ 2010 Express 。

(请勿安装Microsoft Visual Studio 2010 Service Pack 1)

步骤2:从“控制面板\程序和功能”中删除所有Microsoft Visual C ++ 2010可再发行程序包。如果您不这样做,则安装将失败,并显示模糊的“安装过程中出现致命错误”错误。

步骤3:从此处安装用于Visual Studio 2010(v7.1)的Windows SDK的脱机版本。这是64位扩展所必需的。Windows内置了对Pismo等ISO的安装。

步骤4:您需要使用Pismo File Mount Audit Package安装ISO文件。从这里下载Pismo

步骤5:右键单击下载的ISO文件,然后选择Pismo挂载。之后,安装Setup \ SDKSetup.exe而不是setup.exe。

步骤6a:通过将目录更改为C:\ Program Files(x86)\ Microsoft Visual Studio版本\ VC \在C:\ Program Files(x86)\ Microsoft Visual Studio 10.0 \ VC \ bin \ amd64中创建vcvars64.bat文件命令提示符。在命令提示符下键入命令: cd C:\Program Files (x86)\Microsoft Visual Studio version\VC\r

步骤6b:要为针对x86平台的64位命令行构建配置此“命令提示符”窗口,请在命令提示符下输入: vcvarsall x86单击此处以获取更多选项。

步骤7:在命令提示符下,输入以下命令安装PyCrypto: C:\Python3X>pip install -U your_wh_file

Step 1: Install Visual C++ 2010 Express from here.

(Do not install Microsoft Visual Studio 2010 Service Pack 1 )

Step 2: Remove all the Microsoft Visual C++ 2010 Redistributable packages from Control Panel\Programs and Features. If you don’t do those then the install is going to fail with an obscure “Fatal error during installation” error.

Step 3: Install offline version of Windows SDK for Visual Studio 2010 (v7.1) from here. This is required for 64bit extensions. Windows has builtin mounting for ISOs like Pismo.

Step 4: You need to install the ISO file with Pismo File Mount Audit Package. Download Pismo from here

Step 5: Right click the downloaded ISO file and choose mount with Pismo. Thereafter, install the Setup\SDKSetup.exe instead of setup.exe.

Step 6a: Create a vcvars64.bat file in C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\bin\amd64 by changing directory to C:\Program Files (x86)\Microsoft Visual Studio version\VC\ on the command prompt. Type command on the command prompt: cd C:\Program Files (x86)\Microsoft Visual Studio version\VC\r

Step 6b: To configure this Command Prompt window for 64-bit command-line builds that target x86 platforms, at the command prompt, enter: vcvarsall x86 Click here for more options.

Step 7: At the command prompt, install the PyCrypto by typing: C:\Python3X>pip install -U your_wh_file


回答 19

我有python的Pycharm。

  1. pycharm -> file -> setting -> project interpreter

  2. 点击 +

  3. 搜索"pycrypto"并安装软件包

注意:如果尚未安装“适用于Python 2.7的Microsoft Visual C ++编译器”,则它将提示安装,一旦安装完成,请尝试上述步骤,即可正常工作。

I had Pycharm for python.

  1. Go to pycharm -> file -> setting -> project interpreter

  2. Click on +

  3. Search for "pycrypto" and install the package

Note: If you don’t have “Microsoft Visual C++ Compiler for Python 2.7” installed then it will prompt for installation, once installation finished try the above steps it should work fine.


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。