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)
3
  • 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. Commented Mar 10, 2018 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? Commented Mar 11, 2018 at 0:51
  • @DanielRoseman for context, check out this link youtu.be/QVX-etwgvJ8?t=5m37s (It's at the location where the "manage.py" file is being discussed) Commented Mar 11, 2018 at 1:03

3 Answers 3

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.

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

1 Comment

Using a virtualenv is a good way to avoid this sort of confusion.
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.

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.