How to install pip2?

I’ve installed python2 , but for some reason pip2 is missing. There’s only pip3 and pip which points to pip3.

I literally can’t even find in in the repos:

$ dnf whatprovides pip
Last metadata expiration check: 0:00:12 ago on Tue 21 Sep 2021 09:29:01 PM CEST.
python3-pip-21.0.1-2.fc34.noarch : A tool for installing and managing Python3 packages
Repo        : fedora
Matched from:
Provide    : pip = 21.0.1-2.fc34

python3-pip-21.0.1-3.fc34.noarch : A tool for installing and managing Python3 packages
Repo        : @System
Matched from:
Provide    : pip = 21.0.1-3.fc34

python3-pip-21.0.1-3.fc34.noarch : A tool for installing and managing Python3 packages
Repo        : updates
Matched from:
Provide    : pip = 21.0.1-3.fc34

I tried python2 -mpip and python2 -m pip , but that just results in:

/usr/bin/python2: No module named pip

I need this in order to install a couple of dependencies for a python2 script, namely:

pyserial
flask
request
1 Like

Hi,

it doesn’t look like pip2 is in the standard repo. You need to add UnitedRPMs.

Thanks Tom.

1 Like

And now?

$ sudo rpm --import https://raw.githubusercontent.com/UnitedRPMs/unitedrpms/master/URPMS-GPG-PUBLICKEY-Fedora
$ sudo dnf -y install https://github.com/UnitedRPMs/unitedrpms/releases/download/19/unitedrpms-$(rpm -E %fedora)-19.fc$(rpm -E %fedora).noarch.rpm
Last metadata expiration check: 0:07:25 ago on Tue 21 Sep 2021 11:12:40 PM CEST.
unitedrpms-34-19.fc34.noarch.rpm                                                                                                                                                                                                                                                                                                                                                                                                                             2.5 kB/s |  10 kB     00:04    
Dependencies resolved.
=============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================
 Package                                                                                                               Architecture                                                                                                      Version                                                                                                               Repository                                                                                                               Size
=============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================
Installing:
 unitedrpms                                                                                                            noarch                                                                                                            34-19.fc34                                                                                                            @commandline                                                                                                             10 k

Transaction Summary
=============================================================================================================================================================================================================================================================================================================================================================================================================================================================================================
Install  1 Package

Total size: 10 k
Installed size: 4.3 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                                                                                                                                                                                                                                                                                                                                                                                     1/1 
  Installing       : unitedrpms-34-19.fc34.noarch                                                                                                                                                                                                                                                                                                                                                                                                                                        1/1 
  Verifying        : unitedrpms-34-19.fc34.noarch                                                                                                                                                                                                                                                                                                                                                                                                                                        1/1 

Installed:
  unitedrpms-34-19.fc34.noarch                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Complete!
$ sudo dnf install pip2
unitedrpms 34 - x86_64                                                                                                                                                                                                                                                                                                                                                                                                                                        85  B/s | 870  B     00:10    
unitedrpms 34 - x86_64                                                                                                                                                                                                                                                                                                                                                                                                                                       3.0 MB/s | 3.1 kB     00:00    
Importing GPG key 0x3E0265AC:
 Userid     : "unitedrpms (The UnitedRPMs Project) <unitedrpms@protonmail.com>"
 Fingerprint: E95B DEA9 0474 55C0 B9A7 31D3 6AF6 BCF6 3E02 65AC
 From       : /etc/pki/rpm-gpg/URPMS-GPG-PUBLICKEY-Fedora
Is this ok [y/N]: y
unitedrpms 34 - x86_64                                                                                                                                                                                                                                                                                                                                                                                                                                       124 kB/s | 1.2 MB     00:09    

No match for argument: pip2
Error: Unable to find a match: pip2
$ sudo dnf install pip
Last metadata expiration check: 0:00:09 ago on Tue 21 Sep 2021 11:21:09 PM CEST.
Package python3-pip-21.0.1-3.fc34.noarch is already installed.
Dependencies resolved.
Nothing to do.
Complete!
$ sudo dnf install python2
Last metadata expiration check: 0:00:16 ago on Tue 21 Sep 2021 11:21:09 PM CEST.
Package python2.7-2.7.18-11.fc34.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
$ sudo dnf provides pip2
Last metadata expiration check: 0:00:31 ago on Tue 21 Sep 2021 11:21:09 PM CEST.
Error: No Matches found
$ sudo dnf provides pip
Last metadata expiration check: 0:00:35 ago on Tue 21 Sep 2021 11:21:09 PM CEST.
python3-pip-21.0.1-2.fc34.noarch : A tool for installing and managing Python3 packages
Repo        : fedora
Matched from:
Provide    : pip = 21.0.1-2.fc34

python3-pip-21.0.1-3.fc34.noarch : A tool for installing and managing Python3 packages
Repo        : @System
Matched from:
Provide    : pip = 21.0.1-3.fc34

python3-pip-21.0.1-3.fc34.noarch : A tool for installing and managing Python3 packages
Repo        : updates
Matched from:
Provide    : pip = 21.0.1-3.fc34

sudo dnf install python2-pip

1 Like

Usual reminder that Python 2 is long gone and really should not be used.

Therefore, it was also deprecated in Fedora and we no longer include Python 2 packages:

https://fedoraproject.org/wiki/Changes/RetirePython2

https://fedoraproject.org/wiki/Changes/Mass_Python_2_Package_Removal

4 Likes

From what I can tell python2 is still there in the repo, it’s just pip2 that’s missing.
It’s kinda scary to hear that such a widespread package gets removed. I really didn’t expect this to happen on a Linux distro. I mean Linux kinda has a reputation of keeping backwards compatibility to all eternity. Will sh and other wide-spread tools be removed as well?

$ sudo dnf install python2-pip
Fedora 34 - x86_64 - Updates                                                                                                                                                                                                                                                                                                                                                                                                                                  42 kB/s |  22 kB     00:00    
Fedora Modular 34 - x86_64 - Updates                                                                                                                                                                                                                                                                                                                                                                                                                          28 kB/s |  23 kB     00:00    
No match for argument: python2-pip
Error: Unable to find a match: python2-pip

You might check the repos for those libraries and see if they provide a Python 3 version. I’m guessing they do, and you just need to get them from the source.

Then you can avoid Python 2 altogether.


Lol… Python 3 broke basic I/O. Could you imagine if C suddenly broke fprintf(STDOUT, ...).

But I agree with you about backwards compatibility. The Python 3 interpreter should have included code paths to consume Python 2 I/O. Users should not have to do anything special to print to a terminal, like rewrite code after running 2to3. Python should have shouldered the burden, not users.

Hi,

Apologies, on further investigation it doesn’t look like unitedrpms are maintaining pip2 for fedora 34 either.

Thanks Tom.

1 Like

Yes, the python2 package is clearly marked “legacy”. it’s there in case someone absolutely needs it but should be avoided if at all possible. It is no longer “widely used”. All of the Python science stack (numpy/scipy…) have dropped support for Python 2 already. Sure, folks are free to keep supporting it, but as far as the Python developers are concerned, Python 2 is EOL.

I think you have the wrong idea. Linux distributions are downstream. If upstream drops support, why and how will Linux distributions still support some software? Who will fix bugs in the tool, for example?

I’ve really never thought of Linux as keeping backwards compatibility till eternity. it’s just that a lot of users tend to be technically advanced enough to be able to keep old tools working (or they get forked and improved), but there’s a limit to how long tools that upstream developers have declared to be deprecated will be kept.

If you haven’t had a look already, here’s the pip page on pypi—it needs python >= 3.6 now.

https://pypi.org/project/pip/

Here’s the deprecation notice:

https://pip.pypa.io/en/latest/development/release-process/#python-2-support

About sh: as far as I know, it’s a specification, not a tool. On Fedora, it tends to default to bash (but I haven’t done a clean Fedora install in ages so it could point to another shell implementation):

$ ls -lash /usr/bin/sh
0 lrwxrwxrwx. 1 root root 4 Jul 21 19:34 /usr/bin/sh -> bash

https://stackoverflow.com/questions/5725296/difference-between-sh-and-bash

And in general, the answer remains the same: if developers of a tool drop support for a feature etc., so will Fedora. We follow upstream quite closely.

https://docs.fedoraproject.org/en-US/package-maintainers/Staying_Close_to_Upstream_Projects/

The suggested thing to do here, as noted by the pip 2 docs and Python community docs in general, is to migrate to Python 3 (which has been around long enough now to not be still considered “new”). There’s even 2to3 to help with the migration

https://docs.python.org/3/library/2to3.html

It didn’t break basic I/O, it redid how I/O works in Python. That’s why it was a major version release (2 to 3), not a minor or a patch release. There’s only so much you can do while still trying to remain backwards compatible. The Python community is extremely well organised. They do know what they’re doing, and they kept Python 2 support going for ages before deciding to drop it. I mean, look at the overlap between Python 2 and 3 here:

https://python-release-cycle.glitch.me/

That’s quite enough time to migrate really.

Refs:

https://stackoverflow.com/a/9067012/375067

https://docs.python.org/release/3.0.1/whatsnew/3.0.html

1 Like

If the developers of ls, cp, rm etc would stop developing them, would Fedora drop support for those as well?
It just seems weird to me. Sure they may have bugs, but those bugs probably have existed for decades and still these tools were extremely helpful. A bug doesn’t make a program useless.

The issue is that thousands of no-longer-maintained projects have been written with a dependency on python2 and asking random users to port them to python3 is quite unrealistic. And expecting the every developer who has ever released a line of python to translate all of it into pyhton3 is unrealistic as well.
If an existing project depending on python2 works perfectly reliable as-is, I don’t see why you’d need to update the interpreter regularly.

You are comparing apples to oranges.

A programming language such as python has to constantly be updated as hardware is updated and other things change. Even the c language has changed a lot since its first release over 50 years ago.
A programming language is not even close to the same class as simple shell commands.

A simple shell utility such as ls does not change much over the years as the shell itself is very stable. Tools like those follow the normal linux programming mantra – Do one thing and do it very well.

I am sure that if those very basic command tools you named were to be obsoleted that fedora would follow suit, but I cannot see a reason for such a change. Those basic command tools have been around for ages and the code gets improved to keep them current.

3 Likes

Isn’t Python 2 installed by default in Fedora 34? (Or maybe I’m wrong. So let me know.)

When I try, sudo dnf remove python2, it showed me a lot of dependencies. Mainly GIMP is shown in “dependent packages” and a lot list of “Removing unused dependencies”.

So I guess, I can’t remove python 2 :pensive:

Edit:

What I don’t understand is, when I run --whatrequires command for python2, it doesn’t list out Gimp. I wonder why! Shouldn’t it shows me Gimp when I run that command?

pranav@fedora ~> rpm -q --whatrequires python2
no package requires python2
2 Likes

Because the python2.7 package provides lots of capabilities (and files), and gimp may be requiring any one of them to pull it in:

$ rpm -q --provides python2.7
bundled(python2dist(CacheControl)) = 0.12.5
bundled(python2dist(appdirs)) = 1.4.3
bundled(python2dist(certifi)) = 2019.6.16
bundled(python2dist(chardet)) = 3.0.4
bundled(python2dist(colorama)) = 0.4.1
bundled(python2dist(distlib)) = 0.2.9.post0
bundled(python2dist(distro)) = 1.4.0
bundled(python2dist(html5lib)) = 1.0.1
bundled(python2dist(idna)) = 2.8
bundled(python2dist(ipaddress)) = 1.0.22
bundled(python2dist(lockfile)) = 0.12.2
bundled(python2dist(msgpack)) = 0.6.1
bundled(python2dist(packaging)) = 16.8
bundled(python2dist(packaging)) = 19.0
bundled(python2dist(pep517)) = 0.5.0
bundled(python2dist(pip)) = 19.2.3
bundled(python2dist(progress)) = 1.5
bundled(python2dist(pyparsing)) = 2.2.1
bundled(python2dist(pyparsing)) = 2.4.0
bundled(python2dist(pytoml)) = 0.1.20
bundled(python2dist(requests)) = 2.22.0
bundled(python2dist(retrying)) = 1.3.3
bundled(python2dist(setuptools)) = 41.0.1
bundled(python2dist(setuptools)) = 41.2.0
bundled(python2dist(six)) = 1.10.0
bundled(python2dist(six)) = 1.12.0
bundled(python2dist(urllib3)) = 1.25.3
bundled(python2dist(webencodings)) = 0.5.1
deprecated()
libpython2.7.so.1.0()(64bit)
pkgconfig(python-2.7) = 2.7
pkgconfig(python2) = 2.7
python(abi) = 2.7
python2 = 2.7.18-15.fc35
python2-devel = 2.7.18-15.fc35
python2-rpm-macros = 3.9-34
python2-tkinter = 2.7.18-15.fc35
python2.7 = 2.7.18-15.fc35
python2.7(x86-64) = 2.7.18-15.fc35
python27 = 2.7.18-15.fc35

Turns out, it includes the requirement as /usr/bin/python2:

$ rpm -q --requires gimp | grep python
/usr/bin/python2

which is still in use by a few packages (and which is why the python2 package hasn’t been removed from Fedora entirely):

$ sudo dnf repoquery --whatrequires /usr/bin/python2
Last metadata expiration check: 0:02:09 ago on Fri 24 Sep 2021 08:42:45 BST.
NFStest-0:2.1.5-12.fc35.noarch
chrome-remote-desktop-0:91.0.4472.164-2.fc35.x86_64
dmlite-shell-0:1.15.1-2.fc35.x86_64
email2trac-0:2.12.2-8.fc35.x86_64
gimp-2:2.10.24-1.fc35.2.x86_64
gimp-layer-via-copy-cut-0:1.6-20.fc35.x86_64
gimp-resynthesizer-0:2.0.3-7.20190428gitadfa25a.fc35.x86_64
mimms-0:3.2.1-20.fc35.noarch
mplayer-tools-0:1.4.1-0.3.20210313svn.fc35.x86_64
nrdp-client-python-0:1.5.2-9.fc35.noarch
pygobject2-codegen-0:2.28.7-13.fc35.x86_64
pygtk2-0:2.24.0-35.fc35.x86_64

So to see what requires a package, one has to test all the capabilities that the package provides.

As you learned in the bugreport, gimp is moving to Python 3 also, so the next release will hopefully no longer require python 2:

https://bugzilla.redhat.com/show_bug.cgi?id=1737933

Here’s the tracker bug for Python 2 removal:

https://bugzilla.redhat.com/show_bug.cgi?id=1698500

Click the “show advanced fields” button on the right, and then see the long list of bugs that block this tracker bug (so the tracker bug depends on them). A few packages that still require python 2 will have open bugs blocking this one, which should at the beginning of the list (and not struck-through).

I also have python 2 installed only for Gimp, but an alternative of course is to use the Flatpak from Flathub, and that way we won’t need Python 2 installed on our systems.

1 Like

One “trick” one can use to see what other packages actually need from a package is to ask rpm what would happen if you removed it. So instead of (or in addition to) rpm -q --whatrequires python2, try rpm -q --test -e python2.

You have several options:

Create and use Python 2 virtual environment (preferred)

$ sudo dnf install virtualenv python2
....
$ virtualenv --python=python2 venv
...
$ . venv/bin/activate
(venv) $ pip --version
pip 19.2.3 from .../venv/lib/python2.7/site-packages/pip (python 2.7)

Learn more about virtual environments at:

Use ensurepip and install pip for your user (if virtual environments are not desired)

$ sudo dnf install python2
....
$ python2 -m ensurepip --no-default-pip
...
$ pip2 --version
pip 19.2.3 from /home/.../.local/lib/python2.7/site-packages/pip (python 2.7)

Learn more about ensurepip with python2 -m ensurepip --help or in
docs.python.org/2.7/library/ensurepip.html (sorry, new users can only include 2 links in post).

Use ensurepip and install pip systemwide (dangerous)

$ sudo dnf install python2
....
$ sudo python2 -m ensurepip --no-default-pip
...
$ pip2 --version
pip 19.2.3 from /usr/lib/python2.7/site-packages/pip (python 2.7)

Note that using ensurepip with sudo can theoretically break other packages in your system that use Python 2, albeit that risk is small, considering that not many such packages are left in Fedora.

2 Likes

hahaha… i feel compelled to point out that all the sniping back-and-forth about python2 and pip and whether its right to include support or blah blah … all of that noise was shown to basically be worthless, two months later, when someone who actually knows what he’s talking about posted re: ensurepip

miro++
… let this be a lesson to all of us :>

@mathcrimes I feel compelled to point out that this method will break eventually if it hasn’t already. Because as the other posters have pointed out, the python2 package will be removed as well.

It still doesn’t feel right to me… Python2 works and it always has worked, python2 has bugs and it always had bugs. If python2 works now and we don’t touch it, it will still work tomorrow. And even if not, I’m sure many volunteers would be willing to ensure it does.