No module named 'rng_base'

430 Views Asked by At

It's error when I run python manage.py runserver. I google but no answer can fix my error please help.

  File "/Users/ahkomu/Documents/myproject/account/models.py", line 21, in <module>
    from utils.encryption import AESCipher
  File "/Users/ahkomu/Documents/myproject/utils/encryption.py", line 4, in <module>
    from Crypto import Random
  File "/Users/ahkomu/Documents/myproject/venv/lib/python3.9/site-packages/Crypto/Random/__init__.py", line 28, in <module>
    from Crypto.Random import OSRNG
  File "/Users/ahkomu/Documents/myproject/venv/lib/python3.9/site-packages/Crypto/Random/OSRNG/__init__.py", line 32, in <module>
    from Crypto.Random.OSRNG.posix import new
  File "/Users/ahkomu/Documents/myproject/venv/lib/python3.9/site-packages/Crypto/Random/OSRNG/posix.py", line 32, in <module>
    from rng_base import BaseRNG
ModuleNotFoundError: No module named 'rng_base'
2

There are 2 best solutions below

0
occasionalhelper On

It would be helpful to know which version of Crypto/pycrypto you're using but it looks like pycrypto is not well supported: ImportError: No module named Crypto.Cipher

It is possible that your version of Crypto is not compatible with the version of Python 3.9 you have installed since 3.9 was release in 2020.

Try creating your venv with a version of python that existed at the time your version of Crypto was released.

This also discusses an issue with posix: https://github.com/pypa/pipenv/issues/5074

0
JustLearning On

Go to the source code of pycrypto in your local machine and, in file

Random/OSRNG/posix.py

change the line

from rng_base import BaseRNG

by

from Crypto.OSRNG.rng_base import BaseRNG