Installing pip is not working in python < 3.6

PythonPip

Python Problem Overview


I am starting to make a app using bitbucket CI and i am using the following steps to deploy the application and the steps to install pip is failing.

 script:
    - apt-get update
    - apt-get install -y python-dev
    - curl -O https://bootstrap.pypa.io/get-pip.py
    - python get-pip.py
    ... and a few more steps

Dont know why but python get-pip.py step fails with the following error.

Traceback (most recent call last):
  File "get-pip.py", line 24226, in <module>
    main()
  File "get-pip.py", line 199, in main
    bootstrap(tmpdir=tmpdir)
  File "get-pip.py", line 82, in bootstrap
    from pip._internal.cli.main import main as pip_entry_point
  File "/tmp/tmpUgc5ng/pip.zip/pip/_internal/cli/main.py", line 60
    sys.stderr.write(f"ERROR: {exc}")
                                   ^

SyntaxError: invalid syntax

This worked fine upto yesterday. Not sure why this is not working now.

I thought it may be because of windows but i checked in my local machine running linux but these steps but they worked fine.

Python Solutions


Solution 1 - Python

pip 21.0 dropped support for Python 2 and 3.5. The later versions require Python 3.6+. The syntax f"" is supported by Python 3.6+.

To install pip for Python 2.7 install it from https://bootstrap.pypa.io/pip/2.7/ :

- curl -O https://bootstrap.pypa.io/pip/2.7/get-pip.py
- python get-pip.py
- python -m pip install --upgrade "pip < 21.0"

The last command is to upgrade to the latest supported version.

Solution 2 - Python

I solved it by firstly run

python -m pip install --upgrade "pip < 19.2"

and then

python -m pip install --upgrade "pip < 21.0".

It seems reinstall my pip 20.3.4 and the error disappreared!

Solution 3 - Python

> This worked for me:On Mac:

Install pyenv as well as upgrade your python following the instructions on this here

Then in your terminal, if you run python -V and you still get the old version(system predefined version) showing:

To resolve this:

In your terminal run: alias python=python3

Then in your terminal execute python and you should now see that your system is using the python version you installed-:That is if you followed and completed the steps Here Correctly.

python switched

Restart your terminal(close/reopen):

Now you can finally install pip:

Read more about pip instalation steps [here][3]

1:In your terminal execute :$ python -m ensurepip --upgrade

2: Download the script, from https://bootstrap.pypa.io/get-pip.py.

> But..**NB**: instead of navigating to the exact link provided,check > out the available versions of pip here: pipversions

Select the latest version:

pipversions page

Then select getpip.py link to get the file and save it into your directory on your machine:

get-pip cd into the folder where you saved the newly downloaded script and execute:

Then execute:

python get-pip.py

pippy folder

Pip installed successfully:

successfully installed

Solution 4 - Python

For me python 3.5 on aws ec2 below worked curl -O https://bootstrap.pypa.io/pip/3.5/get-pip.py

Then sudo python3.5 get-pip.pyenter image description here

Solution 5 - Python

I have also tried all thing but my solution was download old get-pip version and install.

  1. download: curl -O https://bootstrap.pypa.io/2.7/get-pip.py the file get-pip.py
  2. install: python get-pip.py or python2 get-pip.py
  3. enjoy

This is worked on Debian systems.


Edit: A better solution is always to install a Python version that is long supported. If at all you need to work with an older version - only then must one resort to the above workaround.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSagar AcharyaView Question on Stackoverflow
Solution 1 - PythonphdView Answer on Stackoverflow
Solution 2 - PythonInsteinView Answer on Stackoverflow
Solution 3 - PythonRileyMandaView Answer on Stackoverflow
Solution 4 - PythonNarenderView Answer on Stackoverflow
Solution 5 - Pythonnonnaru 2004View Answer on Stackoverflow