29

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

Duncan Jones
  • 67,400
  • 29
  • 193
  • 254
vedburtruba
  • 1,089
  • 1
  • 9
  • 10
  • On which operating system ? and version ? –  Jul 17 '14 at 13:52
  • 1
    Win7 x86 + Python 3.4.1 – vedburtruba Jul 17 '14 at 13:53
  • Have you installed Paramiko correctly ? (like shown on this link: https://github.com/paramiko/paramiko/blob/master/README) –  Jul 17 '14 at 14:00
  • I have installed Paramiko by PIP, I suppose it is OK. – vedburtruba Jul 18 '14 at 07:36
  • Note that the PyCrypto project has been [discontinued](https://github.com/dlitz/pycrypto/issues/238), apparently the [PyCryptodome project](https://github.com/Legrandin/pycryptodome) aims to be a drop-in replacement. Personally, I've found the [`pycryptography` project](https://cryptography.io/en/latest/) to be a far better API. – Martijn Pieters Apr 28 '18 at 12:55

2 Answers2

68

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

import winrandom

to

from . import winrandom
vedburtruba
  • 1,089
  • 1
  • 9
  • 10
16

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!

Martin Tournoij
  • 26,737
  • 24
  • 105
  • 146
Reed Miller
  • 161
  • 1
  • 3
  • I though this Python was supposed to be such an easy to use language, but as an experienced C# and PhP developer, I keep finding myself googling these kind of fixes for problems that should not be there – Yeronimo Oct 15 '20 at 09:29