djangomanage.py

Syntax error in "manage.py" file - django 2


I do not understand what the problem is but I keep getting a syntax error for the "from exc" line even though I did not alter the code. I have checked for un-closed parentheses and quotes and indentation look right to my beginner's eye. The issue is that this is the out-of-the-box code for the Django 2.0 virtual environment so I can only assume Sublime somehow formatted it wrong when the file was dragged into the text editor?

import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "myproject.settings")
    try:
        from django.core.management import execute_from_command_line
    except ImportError as exc:
        raise ImportError(
            "Couldn't import Django. Are you sure it's installed and "
            "available on your PYTHONPATH environment variable? Did you "
            "forget to activate a virtual environment?"
        ) from exc
    execute_from_command_line(sys.argv)

Solution

  • In command line:

    python3 manage.py runserver
    

    The tutorial I was following used just "python manage.py runserver" instead of "python3" and for some reason there was no error in the tutorial upon running but I received an error on my end.