Invalid Syntax error while installing Django in linux

Viewed 745

I am trying to install Django in linux version x86.I have already installed python. Error I am getting when executed "pip install Django" or "pip3 install Django"

$ pip install django
Traceback (most recent call last):
  File "/home/mandar/.local/bin/pip", line 7, in <module>
    from pip._internal.cli.main import main
  File "/home/mandar/.local/lib/python3.5/site-packages/pip/_internal/cli/main.py", line 60
    sys.stderr.write(f"ERROR: {exc}")
                                   ^
SyntaxError: invalid syntax
4 Answers

EDIT 2:

I suggest you to upgrade Python to a newer version as other user has adviced. This is because f-string was added form Python 3.6 on, check this.


  1. Step 1:- Install ppa:

    sudo add-apt-repository ppa:deadsnakes/ppa
    
  2. Update packeges:

     sudo apt-get update
    
  3. Upgrade python 2.x to python 3.6 or higher

     sudo apt-get install python3.6 
    
  4. PiP installation:

    sudo apt install python3-pip
    

Upgrade pip first (which also upgrades setuptools) and then install django again:

pip install -U pip
pip install django

Or:

pip install --upgrade pip 
pip install django

Alternative 2:

sudo python -m pip install --upgrade --force setuptools
sudo python -m pip install --upgrade --force pip
sudo pip install django==3.1

EDIT: As @Ronald Petit stated,keep this in mind:

Django 3.0+ requires python 3.6+ and you are using python 3.5, you need to either update to a newer python (recommended), or specify Django version to be 2.2 (really not recommended)

hence Run

pip install django==2.2

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 this type of error.

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.

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

pip install -U pip
pip install django
Related