6

I created a virtualenv and downloaded Django with the below commands:

virtualenv tester
source tester/bin/activate
pip install django

and below is the response:

Downloading/unpacking django
  Downloading Django-1.9-py2.py3-none-any.whl (6.6MB): 6.6MB downloaded
Installing collected packages: django
Compiling /home/romaan/workspacepy/tester/build/django/django/conf/app_template/apps.py ...
  File "/home/romaan/workspacepy/tester/build/django/django/conf/app_template/apps.py", line 4
    class {{ camel_case_app_name }}Config(AppConfig):
          ^
SyntaxError: invalid syntax

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

Successfully installed django

Please help me to get rid of this error. All though it says Successfully installed django, I am keen on understanding and getting rid of this syntax error.

Or Should I just wait for the bug fix to happen?

Romaan
  • 2,645
  • 5
  • 32
  • 63

4 Answers4

18

This looks like the setuptools issue mentioned in the Django 1.9 release notes: https://docs.djangoproject.com/en/1.9/releases/1.9/#syntaxerror-when-installing-django-setuptools-5-5-x

Try to run pip install --upgrade pip before running pip install django

mehmet
  • 7,720
  • 5
  • 42
  • 48
Thomas Druez
  • 2,167
  • 1
  • 13
  • 7
  • 3
    If using pip3, should I run `pip3 install -U pip`? If so I think your answer could be improved by including that also. – shrewdbeans Dec 17 '15 at 11:41
1

Those can't, and shouldn't, be fixed. Those are template files which are substituted at project creation time, and are not valid Python syntax. They shouldn't be compiled at install time but rather at project creation time.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
1

These steps worked for me:

$ sudo python -m pip install --upgrade --force setuptools
$ sudo python -m pip install --upgrade --force pip
$ sudo pip install django==1.9
Ganesh Negi
  • 1,939
  • 1
  • 11
  • 9
0

pip install -U pip ran fine but didn't fix my issue

  • I got the same message when I was trying pip install django.
  • I thought to try a previous version so I tried pip install django-1.9.
  • It said "Real name of requirement Django-1.9 is django-503".
  • So pip install Django-503 worked fine for me.