Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Import error: No module named 'secrets' - python manage.py not working after pull to Digital Ocean

I'm following along a course - Django development to deployment.
After pulling it to Digital Ocean everything else ran smoothly. Until
I tried running python manage.py help

(env) djangoadmin@ubuntu-1:~/pyapps/btre_project_4$ python manage.py help

and I get this error.

Traceback (most recent call last):


File "manage.py", line 21, in <module>
    main()
   File "manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/core/management/__init__.py", line 377, in execute
    django.setup()
  File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/__init__.py", line 16, in setup
    from django.urls import set_script_prefix
  File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/urls/__init__.py", line 1, in <module>
    from .base import (
  File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/urls/base.py", line 9, in <module>
    from .exceptions import NoReverseMatch, Resolver404
  File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/urls/exceptions.py", line 1, in <module>
    from django.http import Http404
  File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/http/__init__.py", line 2, in <module>
    from django.http.request import (
  File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/http/request.py", line 10, in <module>
    from django.core import signing
  File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/core/signing.py", line 45, in <module>
    from django.utils.crypto import constant_time_compare, salted_hmac
  File "/home/djangoadmin/pyapps/env/lib/python3.5/site-packages/django/utils/crypto.py", line 6, in <module>
    import secrets
ImportError: No module named 'secrets'

I'm a newbie and have been stuck on this for a while. I just want to know what could possibly cause this.

like image 520
Chief Avatar asked May 01 '20 17:05

Chief


People also ask

How do I fix python import error?

Python's ImportError ( ModuleNotFoundError ) indicates that you tried to import a module that Python doesn't find. It can usually be eliminated by adding a file named __init__.py to the directory and then adding this directory to $PYTHONPATH .

How do I resolve ImportError no module name?

To get rid of this error “ImportError: No module named”, you just need to create __init__.py in the appropriate directory and everything will work fine.

What is ImportError in Python?

In Python, ImportError occurs when the Python program tries to import module which does not exist in the private table. This exception can be avoided using exception handling using try and except blocks. We also saw examples of how the ImportError occurs and how it is handled.


1 Answers

The secrets module was added to Python in version 3.6. Your host is using Python 3.5, hence the secrets module is unavailable. You need a host with Python 3.6+, or a version of Django that doesn't depend on the secrets module

like image 157
snakecharmerb Avatar answered Oct 03 '22 06:10

snakecharmerb