No module named Crypto.PublicKey

When I tried to import the paramiko module, I got following error:

No module named Crypto.PublicKey

That means we need to install pycrypto library. Run following command to install pycrypto library by using pip:

In the installation process I got a another error message:

error: Unable to find vcvarsall.bat

That means we need a C compiler to compile this extension. But we can also download a pre-built extension for windows:


After installing this extension and tried to import “paramiko” module, I got the same error “No module named Crypto.PublicKey” again. This is because the installer installs pycrypto library with lowercase name, but paramiko tries to import it with uppercase name. We should rename crypto directory under “Lib/site-packages” to Crypto, then importing paramiko will work.

  • I hate it here

    My issue was similar since I had “No module named Crypto.PublicKey” like you (didn’t have the windows issue with vcvarsall.bat). I did pip install crypto pycrypto. After import crypto as Crypto, import paramiko I had a new error with no module paramiko.util.

    For linux users just apt-get install python-paramiko will solve the Crypto.PublicKey problem.

  • samwyse

    Did everything listed, including the rename, was still getting Importerror messages for “from paramiko import util” inside paramiko.transport. After lots of searches, gave up for the day. Next morning I restarted IDLE, everything works now.