No module named 'winrandom' when using pycrypto
Question:
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 FilesPythonlibsite-packagesparamiko__init__.py", line 31
, in <module>
from paramiko.transport import SecurityOptions, Transport
File "C:Program FilesPythonlibsite-packagesparamikotransport.py", line 4
7, in <module>
from paramiko.dsskey import DSSKey
File "C:Program FilesPythonlibsite-packagesparamikodsskey.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 FilesPythonlibsite-packagesparamiko__init__.py", line 31
, in <module>
from paramiko.transport import SecurityOptions, Transport
File "C:Program FilesPythonlibsite-packagesparamikotransport.py", line 4
7, in <module>
from paramiko.dsskey import DSSKey
File "C:Program FilesPythonlibsite-packagesparamikodsskey.py", line 26,
in <module>
from Crypto.PublicKey import DSA
File "C:Program FilesPythonlibsite-packagesCryptoPublicKeyDSA.py", line
89, in <module>
from Crypto import Random
File "C:Program FilesPythonlibsite-packagesCryptoRandom__init__.py", li
ne 28, in <module>
from Crypto.Random import OSRNG
File "C:Program FilesPythonlibsite-packagesCryptoRandomOSRNG__init__.p
y", line 34, in <module>
from Crypto.Random.OSRNG.nt import new
File "C:Program FilesPythonlibsite-packagesCryptoRandomOSRNGnt.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
buildtemp.win32-3.4Releasesrcwinrandom.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
Answers:
Problem is solved by editing string in cryptoRandomOSRNGnt.py:
import winrandom
to
from . import winrandom
Super easy fix for ImportError: No module named 'winrandom'
– this is where python is located on my Windows 10 system:
C:UsersCharlesAppDataLocalProgramsPythonPython35
But you have to go further to find the right file to update, so go here:
C:UsersCharlesAppDataLocalProgramsPythonPython35Libsite-packagesCryptoRandomOSRNGnt.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!
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 FilesPythonlibsite-packagesparamiko__init__.py", line 31
, in <module>
from paramiko.transport import SecurityOptions, Transport
File "C:Program FilesPythonlibsite-packagesparamikotransport.py", line 4
7, in <module>
from paramiko.dsskey import DSSKey
File "C:Program FilesPythonlibsite-packagesparamikodsskey.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 FilesPythonlibsite-packagesparamiko__init__.py", line 31
, in <module>
from paramiko.transport import SecurityOptions, Transport
File "C:Program FilesPythonlibsite-packagesparamikotransport.py", line 4
7, in <module>
from paramiko.dsskey import DSSKey
File "C:Program FilesPythonlibsite-packagesparamikodsskey.py", line 26,
in <module>
from Crypto.PublicKey import DSA
File "C:Program FilesPythonlibsite-packagesCryptoPublicKeyDSA.py", line
89, in <module>
from Crypto import Random
File "C:Program FilesPythonlibsite-packagesCryptoRandom__init__.py", li
ne 28, in <module>
from Crypto.Random import OSRNG
File "C:Program FilesPythonlibsite-packagesCryptoRandomOSRNG__init__.p
y", line 34, in <module>
from Crypto.Random.OSRNG.nt import new
File "C:Program FilesPythonlibsite-packagesCryptoRandomOSRNGnt.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
buildtemp.win32-3.4Releasesrcwinrandom.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
Problem is solved by editing string in cryptoRandomOSRNGnt.py:
import winrandom
to
from . import winrandom
Super easy fix for ImportError: No module named 'winrandom'
– this is where python is located on my Windows 10 system:
C:UsersCharlesAppDataLocalProgramsPythonPython35
But you have to go further to find the right file to update, so go here:
C:UsersCharlesAppDataLocalProgramsPythonPython35Libsite-packagesCryptoRandomOSRNGnt.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!