Python 使用 pycrypto 时没有名为“winrandom”的模块

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24804829/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 05:13:54  来源:igfitidea点击:

No module named 'winrandom' when using pycrypto

pythonwindowsparamikopycrypto

提问by vedburtruba

I already spent 2 days trying to install pyCrypto for Paramiko module.

我已经花了 2 天时间尝试为 Paramiko 模块安装 pyCrypto。

So, first issue I had faced was this:

所以,我遇到的第一个问题是:

>>> import paramiko
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Python\lib\site-packages\paramiko\__init__.py", line 31
, in <module>
    from paramiko.transport import SecurityOptions, Transport
  File "C:\Program Files\Python\lib\site-packages\paramiko\transport.py", line 4
7, in <module>
    from paramiko.dsskey import DSSKey
  File "C:\Program Files\Python\lib\site-packages\paramiko\dsskey.py", line 26,
in <module>
    from Crypto.PublicKey import DSA
ImportError: No module named 'Crypto'

It is very fun actually because I use Windows and it doesn't care about uppercase. I changed a folder name from crypto to Crypto and this particular issue disappeared.

这实际上很有趣,因为我使用 Windows 并且它不关心大写。我将文件夹名称从 crypto 更改为 Crypto,此特定问题消失了。

Now it wants winrandom:

现在它想要 winrandom:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Program Files\Python\lib\site-packages\paramiko\__init__.py", line 31
, in <module>
    from paramiko.transport import SecurityOptions, Transport
  File "C:\Program Files\Python\lib\site-packages\paramiko\transport.py", line 4
7, in <module>
    from paramiko.dsskey import DSSKey
  File "C:\Program Files\Python\lib\site-packages\paramiko\dsskey.py", line 26,
in <module>
    from Crypto.PublicKey import DSA
  File "C:\Program Files\Python\lib\site-packages\Crypto\PublicKey\DSA.py", line
 89, in <module>
    from Crypto import Random
  File "C:\Program Files\Python\lib\site-packages\Crypto\Random\__init__.py", li
ne 28, in <module>
    from Crypto.Random import OSRNG
  File "C:\Program Files\Python\lib\site-packages\Crypto\Random\OSRNG\__init__.p
y", line 34, in <module>
    from Crypto.Random.OSRNG.nt import new
  File "C:\Program Files\Python\lib\site-packages\Crypto\Random\OSRNG\nt.py", li
ne 28, in <module>
    import winrandom
ImportError: No module named 'winrandom'

When I try to install it through PIP I fail with:

当我尝试通过 PIP 安装它时,我失败了:

Cannot export PyInit_winrandom: symbol not defined

build\temp.win32-3.4\Release\src\winrandom.o:winrandom.c:(.text+0x12): undefined
 reference to `Py_InitModule'

collect2: ld returned 1 exit status

error: command 'c:\mingw\bin\gcc.exe' failed with exit status 1

Seems like it doesn't support Python3.4.

好像不支持Python3.4。

Is there any way to make it all works in Win7 x86 with Python3.4 installed?

有没有办法让它在安装了 Python3.4 的 Win7 x86 中运行?

Installed modules:

安装的模块:

crypto (1.1.0)
ecdsa (0.11)
Fabric (1.9.0)
paramiko (1.14.0)
pip (1.5.6)
pyasn1 (0.1.7)
pycrypto (2.6.1)
PyYAML (3.11)
rsa (3.1.4)
setuptools (2.1)

Python version 3.4.1

Python 版本 3.4.1

采纳答案by vedburtruba

Problem is solved by editing string in crypto\Random\OSRNG\nt.py:

问题通过编辑crypto\Random\OSRNG\nt.py中的字符串解决:

import winrandom

to

from . import winrandom

回答by Reed Miller

Super easy fix for ImportError: No module named 'winrandom'- this is where python is located on my Windows 10 system:

超级简单的修复ImportError: No module named 'winrandom'- 这是 python 在我的 Windows 10 系统上的位置:

C:\Users\Charles\AppData\Local\Programs\Python\Python35

C:\Users\Charles\AppData\Local\Programs\Python\Python35

But you have to go further to find the right file to update, so go here:

但是您必须进一步找到要更新的正确文件,因此请访问此处:

C:\Users\Charles\AppData\Local\Programs\Python\Python35\Lib\site-packages\Crypto\Random\OSRNG\nt.py

C:\Users\Charles\AppData\Local\Programs\Python\Python35\Lib\site-packages\Crypto\Random\OSRNG\nt.py

Open the nt.pyin any text editor and change just the line near the top:

nt.py在任何文本编辑器中打开并仅更改顶部附近的行:

import winrandom

should be:

应该:

from . import winrandom

Save the file - re-run what you were originally trying to run and you should be good. Hope this helps someone!

保存文件 - 重新运行您最初尝试运行的内容,您应该会很好。希望这对某人有帮助!