Installing pip is not working in python < 3.6
Asked Answered
R

6

72

I am trying to use these steps with bitbucket CI to deploy an application:

 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

However, the python get-pip.py step fails with this 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

Why isn't it working now? Does it depend on the operating system?


For the equivalent issue with upgrading pip in old Python installations, see Upgrading pip fails with syntax error caused by sys.stderr.write(f"ERROR: {exc}").

Roomer answered 24/1, 2021 at 10:7 Comment(4)
https://mcmap.net/q/95108/-pip-install-failing-on-python2-duplicate/7976758, https://mcmap.net/q/95109/-trouble-with-python3-and-pip-duplicate/7976758 Found in stackoverflow.com/…Hippocampus
@Hippocampus Thanks. I'd be glad to accept the answer if you post it. :)Roomer
To make it a better answer I need to know what Python version do you use? 2.7?Hippocampus
@Hippocampus Its just used in bitbucket CI not sure about the version. so i presume its 2.7Roomer
H
113

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.

Hippocampus answered 24/1, 2021 at 13:31 Comment(14)
The upgrade command is not needed, as get-pip.py will install the latest supported versionHenleyonthames
@ColinPickard I prefer to be: a) explicit; b) to write down a command for future reference if a user would ever want to try to upgrade pip once again.Hippocampus
This is fine. But what is the command for 3.5. After downloading from the link?Meson
@Meson The same as in the post: python get-pip.pyHippocampus
This does not work for me - pip stays in version 8.1.1 instead of the installed: Successfully installed pip-20.3.4Announcer
@RoyLevy Fina all pip scripts in the $PATH (type -a pip) and remove excessive/old ones.Hippocampus
Worked for me on Ubuntu Server 16.04.7 with python2.7 and python3.5. Thanks!Nickolenicks
ERROR: This script does not work on Python 2.7 The minimum supported Python version is 3.7. Please use bootstrap.pypa.io/pip/2.7/get-pip.py instead.Dun
@SeniorPomidor Did you read the answer? The URL is clearly in the middle.Hippocampus
@Hippocampus and you? this is not work!!!Dun
@SeniorPomidor Works perfectly: python2.7 get-pip.py -> Successfully installed pip-20.3.4 No problem at all.Hippocampus
@Hippocampus ERROR: No matching distribution found for pip<21.0 /var/tmp/tmpPpfPBt/pip.zip/pip/_vendor/urllib3/util/ssl_.py:164: InsecurePlatformWarning: A true SSLContext object is not available.Dun
@SeniorPomidor That's a different error, not what you said before.Hippocampus
it is same error just full output does not fit hereDun
U
11

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!

Ungulate answered 1/6, 2021 at 3:40 Comment(3)
This is quite strange but, yeah it fixed my problem too.Denudation
Same thing happened to me. pip is wonky as hell.Lurie
You're a life saver. Installing pip is apparently rocket science, but this works.Manipulator
K
2

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

Kymric answered 10/11, 2021 at 22:27 Comment(0)
S
1

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

Saccharo answered 11/11, 2021 at 3:2 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Circulation
E
0

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.

Efferent answered 30/1, 2021 at 17:12 Comment(1)
/urllib3/util/ssl_.py:164: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see urllib3.readthedocs.io/en/latest/…Dun
M
-1
  1. Uninstall existing pip on your machine

  2. Run this cmd in ubuntu or any linux machine

    curl https://bootstrap.pypa.io/pip/3.5/get-pip.py -o get-pip.py
    python3 get-pip.py
    

It will work

Misology answered 22/6, 2022 at 18:4 Comment(2)
As it's currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked and to explain how this answer is different from others already posted. You can find more information on how to write good answers in the help center.Procephalic
This seems to be a restatement of previous answers anyway.Hexastyle

© 2022 - 2024 — McMap. All rights reserved.