使用pycrypto时没有名为'winrandom'的模块

时间:2014-07-17 13:24:27

标签: python windows paramiko pycrypto

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

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

>>> 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'

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

现在它想要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'

当我尝试通过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

似乎它不支持Python3.4。

有没有办法让它在安装了Python3.4的Win7 x86中都能正常工作?

已安装的模块:

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 3.4.1版

2 个答案:

答案 0 :(得分:60)

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

import winrandom

from . import winrandom

答案 1 :(得分:12)

C:\Users\Charles\AppData\Local\Programs\Python\Python35的超级简单修复 - 这就是我的Windows 10系统上python的位置:

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

但你必须进一步找到要更新的正确文件,所以请到这里:

nt.py

在任何文本编辑器中打开import winrandom ,只更改顶部附近的行:

from . import winrandom

应该是:

{{1}}

保存文件 - 重新运行您最初尝试运行的内容,您应该保持良好状态。希望这有助于某人!