0

I'm trying out AES encryption on Python and my code is fine but in from Crypto import Random, the Random is giving an error. When I run the code, I get the following traceback:

Traceback (most recent call last):
  File "C:/Users/RedCode/PycharmProjects/SecurityApps/Encryption/AES.py", line 3, in <module>
  from Crypto import Random
  ImportError: cannot import name 'Random'

How can I correct this issue?

If it helps, I checked my site-package folder and I have pycrypto, pycryptodome, pycryptodomex, Crypto, and crypto-1.4.1.

RedCode
  • 363
  • 1
  • 6
  • 23
  • Possible duplicate of [Tweepy: ImportError: cannot import name Random](https://stackoverflow.com/questions/25750961/tweepy-importerror-cannot-import-name-random) – Qiu Jun 07 '17 at 13:11
  • 1
    @Qiu Unless RedCode can confirm this is issue I won't vote to close the question as a duplicate; I think closing it down because RedCode has defined a `random.py` is premature. RedCode, is it a dupe or not? – Maarten Bodewes Jun 07 '17 at 13:48
  • Possible duplicate of [from Crypto import Random -> ImportError: cannot import name Random](https://stackoverflow.com/questions/7210873/from-crypto-import-random-importerror-cannot-import-name-random). @phihag's answer and comments seem particularly relevant. – jww Jun 08 '17 at 02:17
  • If I am parsing this question and the potential dup properly, then... Your version of the `Crypto` class is `1.4.1` and it is too old. According to the potential dup, you need version `2.1.0` of `Crypto` or above. – jww Jun 08 '17 at 02:44
  • I tried the solutions on both questions and neither worked. But they gave me some ideas. I resolved the issue in my answer. – RedCode Jun 08 '17 at 05:06

1 Answers1

0

Okay, so my issue was that PyCharm was not reading the site-packages folder properly. I had a Crypto package folder but it wasn't the proper one as it was missing a lot of sub-folders. I can't remember where I downloaded it from but it was basically given the wrong name.

By some random luck I found the proper Crypto folder inside the pycryptodome-3.4.6-py3.6-win32.egg folder, which contained the Random package inside it (along with other packages). So I removed the Crypto folder I had, and replaced it with the one I found and everything works now

RedCode
  • 363
  • 1
  • 6
  • 23