2

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
2
  • What distro are you running, and is this arm, x86, or x64? Please put more information into your questions. Commented Jan 25, 2021 at 15:31
  • This is solved! {Adding this comment as stackoverflow is not letting me add more questions due to this :)} Commented Jun 4 at 14:22

4 Answers 4

2

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
Sign up to request clarification or add additional context in comments.

4 Comments

actually pip command isnt working , both alternative are giving same error ,I tried to uninstall pip but it is also giving me same error
actually pip command is not working its giving same syntax errors, even pip version command isn't working
python-pip is already the newest version (8.1.1-2ubuntu0.6). 0 upgraded, 0 newly installed, 0 to remove and 17 not upgraded.
That's really Cool ;)
2

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

2 Comments

@MandarRemane You must be still using python 3.5 as the error is marking an f string which is not available in python 3.5 but in 3.6
yeah error was solved! Thanks for the info
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

Comments

2

Pip has already dropped support for Python2 (https://pip.pypa.io/en/stable/news/). I suggest you to use older version of Pip, or to switch to Python3.6.

Syntax error near fsting means that your env doesn't support fstings (it is introduced in Python3.6

--edit--

You can isntall Python with this tutorial: https://www.2daygeek.com/install-python-3-on-centos-6/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.