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?
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
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.
Rename crypto directory under “Lib/site-packages” to Crypto, then importing will work.
If you are using Python 3.7, it already exists. Just change the folder name in C:UsersusernameAppDataLocalProgramsPythonPython37Libsite-packages
from crypto to Crypto
Install Pycryptodome using python3 -m pip install pycryptodome
. crypto.PublicKey.RSA
is not proper, instead try using from Crypto.PublicKey import RSA
.
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
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?
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
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.
Rename crypto directory under “Lib/site-packages” to Crypto, then importing will work.
If you are using Python 3.7, it already exists. Just change the folder name in C:UsersusernameAppDataLocalProgramsPythonPython37Libsite-packages
from crypto to Crypto
Install Pycryptodome using python3 -m pip install pycryptodome
. crypto.PublicKey.RSA
is not proper, instead try using from Crypto.PublicKey import RSA
.
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