问题
I already spent 2 days trying to install pyCrypto for Paramiko module.
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.
Now it wants 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:
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.
Is there any way to make it all works in Win7 x86 with Python3.4 installed?
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
回答1:
Problem is solved by editing string in crypto\Random\OSRNG\nt.py:
import winrandom
to
from . import winrandom
回答2:
Super easy fix for ImportError: No module named 'winrandom' - this is where python is located on my Windows 10 system:
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
Open the nt.py in any text editor and change just the line near the top:
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!
来源:https://stackoverflow.com/questions/24804829/no-module-named-winrandom-when-using-pycrypto