Python ImportError No module named crypto.PublicKey.RSA

Question:

When I try to execute a python program, I get this from terminal

Traceback (most recent call last):
File "ring.py", line 1, in <module>
import os, hashlib, random, crypto.PublicKey.RSA
ImportError: No module named crypto.PublicKey.RSA

I have no idea how to solve this and other questions have proven completely useless to my situation.

Is the module there but in the wrong place?
Should I download modules from somewhere like for node.js?
Or it’s more like Java?

Asked By: user3753342

||

Answers:

Yes, you have to install it. Try this from terminal:

sudo apt-get install python-pip
pip install crypto

For mac, try to use easy_install.

sudo easy_install python-pip
pip install crypto

If crypto is installed properly, import like below:

 from Crypto.PublicKey import RSA
Answered By: Ahsanul Haque

The correct package to install is pycrypto.

pip install pycrypto

Should work on most platforms, otherwise get Pip from https://pip.pypa.io/en/stable/

Edit: As mentioned in the comments below, pip install pycryptodome installs a newer, drop-in replacement for pycrypto and is the better option going forward.

Answered By: Fredrik Håård

Rename crypto directory under “Lib/site-packages” to Crypto, then importing will work.

Answered By: CENTURION

If you are using Python 3.7, it already exists. Just change the folder name in C:UsersusernameAppDataLocalProgramsPythonPython37Libsite-packages
from crypto to Crypto

Answered By: user11263186

Install Pycryptodome using python3 -m pip install pycryptodome. crypto.PublicKey.RSA is not proper, instead try using from Crypto.PublicKey import RSA.

Answered By: Sidd_Tim

At line:1 char:1

  • from Crypto.PublicKey import RSA

The ‘from’ keyword is not supported in this version of the language.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ReservedKeywordNotAllowed

Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.