1

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)
Mountain Scott
  • 183
  • 4
  • 15
  • 3
    What version of Python are you using? Django 2.0 is only compatible with Python 3, and this syntax is invalid in Python 2. – Daniel Roseman Mar 10 '18 at 13:01
  • @DanielRoseman I'm using Python 3 and I have Django 2.0 installed on my mac. But I also have Django 1.11 installed. Maybe my computer defaults to the wrong version? – Mountain Scott Mar 11 '18 at 00:51
  • @DanielRoseman for context, check out this link https://youtu.be/QVX-etwgvJ8?t=5m37s (It's at the location where the "manage.py" file is being discussed) – Mountain Scott Mar 11 '18 at 01:03

3 Answers3

2

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.

Mountain Scott
  • 183
  • 4
  • 15
1

If youre manage.py starts with "#!/usr/bin/env python", try changing it to "#!/usr/bin/env python3". This will force it to use Python 3.xx. It worked for me.

CORals
  • 59
  • 1
  • 5
0

Use "python3" if you have python 3X "python3 manage.py runserver" it work

CrltsMrtnz
  • 49
  • 1
  • 5