[Fixed]-Django 1.9 Installation SyntaxError: invalid syntax

23👍

This is a common issue caused by an outdated version of setuptools (5.5.x):

When installing Django 1.9+ with setuptools 5.5.x, you’ll see:

Compiling django/conf/app_template/apps.py ...   File
"django/conf/app_template/apps.py", line 4
    class {{ camel_case_app_name }}Config(AppConfig):
          ^ SyntaxError: invalid syntax

Compiling django/conf/app_template/models.py ...   File
"django/conf/app_template/models.py", line 1
    {{ unicode_literals }}from django.db import models
                             ^ SyntaxError: invalid syntax

It’s safe to ignore these errors (Django will still install just fine), but you
can avoid them by upgrading setuptools to a more recent version. If
you’re using pip, you can upgrade pip using pip install -U pip which
will also upgrade setuptools.

(Source: https://docs.djangoproject.com/en/1.9/releases/1.9/#syntaxerror-when-installing-django-setuptools-5-5-x)


The solution is to upgrade pip first (which also upgrades setuptools) and then install django again:

pip install -U pip
pip install django

Leave a comment