8

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.

2 Answers 2

9

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

Sign up to request clarification or add additional context in comments.

4 Comments

Just Checked: Python 3.5.2. Which is easier to change host or Django. It sounds like I'd have to make huge changes to the project if I changed Django versions - or am I wrong.
Yah fixed it - used a host with Python 3.6
I encounter the same error today with Python 3.9 Anyone has any idea?
@chocolatte Double check the expected version of Python is running the code, and that you don't have a secrets.py in your own code that could be causing problems. If you are certain that it is being executed by Python 3.6+, open a new question and include the complete error traceback.
1

Had the same issue, solved it by specifying the python version I have installed. i.e

$ python3
>>> import secrets
>>> secrets.token_hex(16)

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.