25

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?

2
  • after successfully installing crypto (thanks guys) now unfortunately the error just shifted to No module named PublicKey.RSA Oct 7, 2015 at 18:40
  • I even installed the package from the tar.gz after downloading it from the website. But still nothing Oct 7, 2015 at 19:23

7 Answers 7

54

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.

1
  • 2
    Now I think pycryptodome is the more generally used one.
    – Arya
    Aug 22, 2019 at 23:26
13

If you are using Python 3.7, it already exists. Just change the folder name in C:\Users\username\AppData\Local\Programs\Python\Python37\Lib\site-packages from crypto to Crypto

1
  • Hello sir, I have checked the folder path, but the 'Crypto' folder doesn't exist. What to do in this case? looking forward to here from you. Mar 19, 2022 at 15:36
4

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

1
  • Hello sir, I have checked the folder path, but the 'Crypto' folder doesn't exist. What to do in this case? looking forward to here from you. Mar 19, 2022 at 15:36
1

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
8
  • It's important to know what if using Python 3.x you need to specify pip3, for Ubuntu at least.
    – Leb
    Oct 7, 2015 at 17:43
  • what about mac? i don't have apt-get here Oct 7, 2015 at 18:30
  • Do you have easy_install? Oct 7, 2015 at 18:32
  • 2
    installing crypto didn't work for me : Fredrik Håård's answer below did: pip install pycrypto
    – datakid
    May 11, 2016 at 3:35
  • 2
    @datakid use pip install cryptodome if you are on Windows.
    – ankostis
    Jun 7, 2018 at 21:24
0

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

0

Uninstalling and reinstalling worked for me.

py -m pip uninstall pycryptodome

then

py -m pip install pycryptodome
0

solution: If you are using Python 3.7, it already exists. Just change the folder name in C:\Users\username\AppData\Local\Programs\Python\Python37\Lib\site-packages from crypto to Crypto

New contributor
umut is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.