Updating pip with Python 2.7.5 breaks pip
See original GitHub issueDescription
When updating to pip 21.1.2 for Python 2.7.5, pip is broken (usage of f-string for formatting strings, giving a “invalid syntax” message).
Expected behavior
As I understand, Python 2 is not supported by pip anymore, but pip should neither :
- suggest to upgrade to 21.1.2 when running with Python 2;
- actually upgrade to a script with invalid syntax
pip version
21.1.2
Python version
2.7.5
OS
CentOS Linux release 7.9.2009 (Core)
How to Reproduce
- When pip has been upgraded to version 21.1.2 it fails
- We can workaround this by uninstalling pip and resinstalling old version from yum package:
- Then upgrading pip with itself to a known-to-work version (here version 20.0.2), but pip still insists that we should update to version 21.1.2.
Output
1. When pip has been upgraded to version 21.1.2 it fails like this:
$ python -m pip --version
Traceback (most recent call last):
File "/usr/lib64/python2.7/runpy.py", line 162, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/lib64/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/usr/lib/python2.7/site-packages/pip/__main__.py", line 29, in <module>
from pip._internal.cli.main import main as _main
File "/usr/lib/python2.7/site-packages/pip/_internal/cli/main.py", line 58
sys.stderr.write(f"ERROR: {exc}")
^
SyntaxError: invalid syntax
- We can workaround this by uninstalling pip and resinstalling old version from yum package:
$ sudo yum remove python-pip
[sudo] password for admin:
Loaded plugins: fastestmirror
Resolving Dependencies
--> Running transaction check
---> Package python2-pip.noarch 0:8.1.2-14.el7 will be erased
--> Finished Dependency Resolution
Dependencies Resolved
==================================================================================================================================================================
Package Arch Version Repository Size
==================================================================================================================================================================
Removing:
python2-pip noarch 8.1.2-14.el7 @epel 7.2 M
Transaction Summary
==================================================================================================================================================================
Remove 1 Package
Installed size: 7.2 M
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Erasing : python2-pip-8.1.2-14.el7.noarch 1/1
warning: file /usr/lib/python2.7/site-packages/pip/wheel.pyo: remove failed: No such file or directory
[...]
warning: file /usr/lib/python2.7/site-packages/pip-8.1.2-py2.7.egg-info: remove failed: No such file or directory
warning: file /usr/bin/pip: remove failed: No such file or directory
Verifying : python2-pip-8.1.2-14.el7.noarch 1/1
Removed:
python2-pip.noarch 0:8.1.2-14.el7
Complete!
$ sudo rm -fr /usr/lib/python2.7/site-packages/pip
[sudo] password for admin:
$ sudo rm -fr /usr/lib/python2.7/site-packages/pip-2*
$ sudo yum install python-pip
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink | 13 kB 00:00:00
* base: centos.crazyfrogs.org
* epel: d2lzkl7pfhq30w.cloudfront.net
* extras: centos.crazyfrogs.org
* updates: centos.crazyfrogs.org
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
epel | 4.7 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
(1/2): epel/x86_64/updateinfo | 1.0 MB 00:00:00
(2/2): epel/x86_64/primary_db | 6.9 MB 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package python2-pip.noarch 0:8.1.2-14.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==================================================================================================================================================================
Package Arch Version Repository Size
==================================================================================================================================================================
Installing:
python2-pip noarch 8.1.2-14.el7 epel 1.7 M
Transaction Summary
==================================================================================================================================================================
Install 1 Package
Total download size: 1.7 M
Installed size: 7.2 M
Is this ok [y/d/N]: y
Downloading packages:
python2-pip-8.1.2-14.el7.noarch.rpm | 1.7 MB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : python2-pip-8.1.2-14.el7.noarch 1/1
Verifying : python2-pip-8.1.2-14.el7.noarch 1/1
Installed:
python2-pip.noarch 0:8.1.2-14.el7
Complete!
- then upgrading pip with itself to a known-to-work version (here version 20.0.2)
$ sudo pip2 install --upgrade pip==20.0.2
Collecting pip==20.0.2
Cache entry deserialization failed, entry ignored
Using cached https://files.pythonhosted.org/packages/54/0c/d01aa759fdc501a58f431eb594a17495f15b88da142ce14b5845662c13f3/pip-20.0.2-py2.py3-none-any.whl
Installing collected packages: pip
Found existing installation: pip 8.1.2
Uninstalling pip-8.1.2:
Successfully uninstalled pip-8.1.2
Successfully installed pip-20.0.2
You are using pip version 20.0.2, however version 21.1.2 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
WARNING: You are using pip version 20.0.2; however, version 21.1.2 is available.
You should consider upgrading via the '/usr/bin/python2 -m pip install --upgrade pip' command.
Code of Conduct
- I agree to follow the PSF Code of Conduct.
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
pip upgrade inside python 2.7 environment breaks pip #9724
The good news is that once you've upgraded, the new pip will be able to detect that newer versions don't support Python 2.7,...
Read more >pip install/upgrade fails with SyntaxError - Stack Overflow
You have a Python version lower than 3.6. Pip has dropped the support for your Python version. I recommend you to upgrade your...
Read more >On the old python 2.7.5 version, the pip install package does ...
I have Python 2.7.5 and pip 20.2.4 installed on my computer. When I use the pip install command it gives an SSL connection...
Read more >Pip - PyPI
pip is the package installer for Python. You can use pip to install packages from the Python Package Index and other indexes.
Read more >How to Install PIP on CentOS, Ubuntu and Windows?
Make sure to upgrade pip, though. Use the below command to check whether pip is installed: CentOS/Ubuntu: $ python -m pip --version.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@uranusjr you’re right!
When listing installed packages (for example), the warning is different (version 20.3.4 is suggested for upgrading instead of 21.1.2):
And when actually upgrading (without version constraint), pip goes up to version 20.3.4 and not 21.1.2:
No more incentives for upgrading are issued afterwards.
Thanks for all these clarifications.
Have a nice day.
Actually, a reasonably up-to-date pip will not warn about incompatible pip versions (and will also stop you from doing that). But the built-in pip in Python 2.7 is from like five years ago and doesn’t have that functionality. This applies not only to pip but almost every projects that is still being worked on, everyone is slowly dropping Python 2 support. If you somehow still must run Python 2, you probably shouldn’t upgrade anything unless you really really know what the new version is changing.