Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid Syntax error while installing Django in linux

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
like image 284
DarkPhoenix Avatar asked May 02 '26 09:05

DarkPhoenix


2 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.

  • PEP 498 -- Literal String Interpolation.

  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
like image 82
Federico Baù Avatar answered May 03 '26 22:05

Federico Baù


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)

To install an specific django version just do:

pip install django==x.x.x

x.x.x can be replaced for example with 2.2

docs: https://docs.djangoproject.com/en/3.1/faq/install/#faq-python-version-support

like image 32
Ronald Petit Avatar answered May 03 '26 23:05

Ronald Petit



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!