It appears that dnf uses python internally. So removing it forcefully will break you package management, and then you are in a much worse situation.

You could remove all installed python packages like this, while still keeping python itself:

for package in $(pip3 freeze); do pip3 uninstall -y $package; done

If that doesn't help because the standard library of Python is broken then try

dnf reinstall python3 -y
Answer from Harald Nordgren on Stack Overflow
Discussions

uninstall old version python (fedora) - Stack Overflow
i need to install python 3.2 but i have python 2.7 installed already on fedora 16. I download python 3.2 and installed it but when i run this command: >python I got: Python 2.7.3 (default, Jul... More on stackoverflow.com
🌐 stackoverflow.com
python in fedora
Unless you really want to brick your system, don't try to remove system python. More on reddit.com
🌐 r/Fedora
10
4
December 12, 2024
How to manage python's version?
I’m currently using Fedora 39. The first installation of Fedora was F36, then I upgraded to F37, then F38 then F39. On my system, I have 3 versions of python: /usr/bin/python /usr/bin/python3 /usr/bin/python3.12 and (for pip) /usr/bin/pip /usr/bin/pip3 /usr/bin/pip-3 /usr/bin/pip3.12 ... More on discussion.fedoraproject.org
🌐 discussion.fedoraproject.org
9
0
November 16, 2023
Is there a way to downgrade python on Fedora 35?
Kind of forces me to not use system python installation for regular use Messing about with Python and packages at the system level has the potential to screw up lots of distributions. Use virtual environments More on reddit.com
🌐 r/Fedora
13
5
November 13, 2021
Top answer
1 of 3
4

which python only tells you the executable that would be run with the command python, i.e. it typically returns exactly one result per argument, unless you specify -a, in which case it searches all the directories in the $PATH environment variable. But in all cases it is the same python command.

If you want to know how many versions of python are installed on your system, you're better off with locate /python | grep /bin or ls -l /usr/bin/python* or yum --showduplicates list python.

As for your two python instances, chances are one of them is a [symbolic] link: check with which -a python | xargs ls -li. If you want to remove a specific version of python then you'll have to specify that version number on the yum command line, e.g. : yum remove python-2.7.2.el5s2.

EDIT: As mattdm reports, /bin is a symbolic link to /usr/bin on Fedora. Consequently you cannot delete python from either of these locations with rm otherwise you'd end up deleting python at all. The -i argument to ls in which -a python | xargs ls -li will in this case show that both python instances have the same inode.

Just note that you are not required to manually remove version-specific packages since the package manager's purpose is precisely to pull versions adequately, as per dependency requirements. If a specific version is installed then it is there for a good reason. Removing one is likely to rid other packages along.

Finally use your distribution's package manager by all means to install packages and their dependencies, especially those that belong to the distribution's repository... unless impossible otherwise. I might be wrong but if you count on pip to update some of the main packages then the package manager will be confused and most probably mess up with the dependencies you satisfied by hand. (In fact it's the other way around: letting pip manage dependencies will likey mess up with yum.)

2 of 3
3

On all recent Fedora releases, /bin is a symlink to /usr/bin — which means if you look in /bin, you actually get redirected to the /usr/bin. However, both appear in $PATH (hmmm; that probably should be cleaned up), and that's what you're seeing with which -a python — two ways to get to an actually-identical binary.

So, there's no problem here.

(Note, though, that mixing pip and rpm (yum) installation can give confusing results and possibly install duplicate versions of things.)

🌐
Fedora Docs
docs.fedoraproject.org › sv › fedora › f33 › release-notes › developers › Development_Python
Python :: Fedora Docs
python3.8 -m pip uninstall $(python3.8 -m pip list --user | cut -d" " -f1) Optionally, clean up the now empty directory structure: ... Additionally, if you have any pip packages installed using sudo, run the following commands before running ...
🌐
Reddit
reddit.com › r/fedora › python in fedora
r/Fedora on Reddit: python in fedora
December 12, 2024 -

Fedora has been the distribution with fewest bugs and very up to date software, likely thanks to best testing out of all distribution. Thank you to all contributors for making it so great.

One of the very few annoyances has been python updates being too fast and so I've had to implement some workarounds like virtualenvs and installing multiple versions of python.

Since F41 we have dnf5 which no longer needs python and is much faster. I am very happy about that and so I tried to uninstall python all together. It turns out there are two packages which depend on python and many people probably use at least one of them:

  1. flatpak

  2. hyprland

flatpak is written in c with some support for python scripting and hyprland is written in c++ with zero python.

What are the reasons that these packages depend on python?

Can we run flatpaks without python installed?

🌐
Fedora Discussion
discussion.fedoraproject.org › ask fedora
How to manage python's version? - Fedora Discussion
November 16, 2023 - I’m currently using Fedora 39. The first installation of Fedora was F36, then I upgraded to F37, then F38 then F39. On my system, I have 3 versions of python: /usr/bin/python /usr/bin/python3 /usr/bin/python3.12 and (for pip) /usr/bin/pip /usr/bin/pip3 /usr/bin/pip-3 /usr/bin/pip3.12 /usr/bin/p…
Find elsewhere
🌐
The Fedora Project
fedoraproject.org › wiki › Changes › F31_Mass_Python_2_Package_Removal
Changes/F31 Mass Python 2 Package Removal - Fedora Project Wiki
October 9, 2021 - Finally, we'll use an expedited process to remove non-installable Python 2 packages from the distro. ... Over a thousand packages in Fedora still depend on Python 2, which will reach End of Life (EOL) on 2020-01-01, shortly after the expected Fedora 31 release date.
Top answer
1 of 3
5

As Kimvas has noted, you can get a list of all removed packages from /var/log/yum.log. Re-installing them with yum is unlikely to work though because yum is a python script and python was removed from your system.

What you can try though is downloading removed rpm's from Fedora mirrors then booting from some Fedora bootable disk, chroot'ing to the system partition and installing those rpm's using rpm.

It is a good idea to keep /home and system / partitions separate, so that when / gets wiped or reinstalled all your data in /home stays intact.

2 of 3
1

You deleted GNOME GUI among other things. If you recreate the list of packages you deleted and then use yum to install them you should be able to restore you distro to its former glory.

david@david-AOA150:~$ sudo apt-get remove python
[sudo] password for david: 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libssl-dev libssl-doc zlib1g-dev libexpat1-dev python2.7-dev
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  libpython3.2 python3 python3-minimal python3-uno python3.2 python3.2-minimal
Suggested packages:
  python3-doc python3-tk python3.2-doc
The following packages will be REMOVED:
  activity-log-manager-control-center aisleriot apparmor apport apport-gtk
  apt-xapian-index aptdaemon apturl apturl-common bluez bluez-alsa
  bluez-gstreamer checkbox checkbox-qt command-not-found compiz compiz-gnome
  compiz-plugins-main-default compizconfig-backend-gconf deja-dup duplicity
  evolution-data-server firefox firefox-globalmenu firefox-gnome-support
  foomatic-db-compressed-ppds gcj-4.6-jre-lib gconf2 gedit
  gir1.2-ubuntuoneui-3.0 gksu gnome-bluetooth gnome-control-center gnome-media
  gnome-menus gnome-orca gnome-sudoku gnome-terminal gnome-terminal-data
  gnome-user-share gstreamer0.10-gconf gwibber gwibber-service
  gwibber-service-facebook gwibber-service-identica gwibber-service-twitter
  hplip hplip-data ibus ibus-pinyin ibus-table indicator-datetime
  indicator-power jockey-common jockey-gtk landscape-client-ui-install
  language-selector-common language-selector-gnome launchpad-integration
  libbonoboui2-0 libcanberra-gtk-module libcanberra-gtk3-module
  libcompizconfig0 libdb5.1-java-gcj libfolks-eds25 libgcj-bc libgcj-common
  libgcj12 libgksu2-0 libgnome-media-profiles-3.0-0 libgnome2-0
  libgnome2-common libgnomeui-0 libgnomevfs2-0 libgnomevfs2-common
  libgweather-3-0 libgweather-common libgwibber-gtk2 libgwibber2
  libmetacity-private0 libpurple-bin libreoffice-gnome libswt-gnome-gtk-3-jni
  libsyncdaemon-1.0-1 libubuntuoneui-3.0-1 light-themes lsb-release metacity
  metacity-common nautilus-dropbox nautilus-share network-manager-gnome
  nvidia-common onboard oneconf openprinting-ppds printer-driver-foo2zjs
  printer-driver-postscript-hp printer-driver-ptouch printer-driver-pxljr
  printer-driver-sag-gdi printer-driver-splix python python-appindicator
  python-apport python-apt python-apt-common python-aptdaemon
  python-aptdaemon.gtk3widgets python-aptdaemon.pkcompat python-brlapi
  python-cairo python-chardet python-configglue python-crypto python-cups
  python-cupshelpers python-dateutil python-dbus python-debian
  python-debtagshw python-defer python-dev python-dirspec
  python-egenix-mxdatetime python-egenix-mxtools python-gconf python-gdata
  python-gdbm python-gi python-gi-cairo python-gnomekeyring
  python-gnupginterface python-gobject python-gobject-2 python-gpgme
  python-gst0.10 python-gtk2 python-httplib2 python-ibus python-imaging
  python-keyring python-launchpadlib python-lazr.restfulclient python-lazr.uri
  python-libproxy python-libxml2 python-louis python-mako python-markupsafe
  python-notify python-oauth python-openssl python-packagekit python-pam
  python-pexpect python-pip python-piston-mini-client python-pkg-resources
  python-problem-report python-protobuf python-pyatspi2 python-pycurl
  python-pyinotify python-pypcap python-renderpm python-reportlab
  python-reportlab-accel python-serial python-setuptools python-simplejson
  python-smbc python-software-properties python-speechd python-support
  python-twisted-bin python-twisted-core python-twisted-names
  python-twisted-web python-ubuntu-sso-client python-ubuntuone-client
  python-ubuntuone-control-panel python-ubuntuone-storageprotocol python-uno
  python-virtkey python-wadllib python-xapian python-xdg python-xkit
  python-zeitgeist python-zope.interface rhythmbox rhythmbox-mozilla
  rhythmbox-plugin-cdrecorder rhythmbox-plugin-magnatune
  rhythmbox-plugin-zeitgeist rhythmbox-plugins rhythmbox-ubuntuone
  sessioninstaller software-center software-center-aptdaemon-plugins
  software-properties-common software-properties-gtk
  system-config-printer-common system-config-printer-gnome
  system-config-printer-udev totem totem-mozilla totem-plugins ubuntu-artwork
  ubuntu-desktop ubuntu-minimal ubuntu-sso-client ubuntu-sso-client-gtk
  ubuntu-standard ubuntu-system-service ubuntuone-client
  ubuntuone-client-gnome ubuntuone-control-panel ubuntuone-couch
  ubuntuone-installer ufw unattended-upgrades unity unity-2d unity-common
  unity-lens-applications unity-lens-video unity-scope-musicstores
  unity-scope-video-remote update-manager update-manager-core update-notifier
  update-notifier-common usb-creator-common usb-creator-gtk xdiagnose
  xul-ext-ubufox zeitgeist zeitgeist-core zeitgeist-datahub
The following NEW packages will be installed:
  libpython3.2 python3 python3-minimal python3-uno python3.2 python3.2-minimal
0 upgraded, 6 newly installed, 241 to remove and 0 not upgraded.
Need to get 5,701 kB of archives.
After this operation, 240 MB disk space will be freed.
Do you want to continue [Y/n]? n
Abort.

I am running ubuntu 12.04, but it looks like I would have done the same thing

🌐
GitHub
github.com › AUTOMATIC1111 › stable-diffusion-webui › issues › 8067
[Bug]: Uninstallable with fedora 37 / Python 3.11.1 · Issue #8067 · AUTOMATIC1111/stable-diffusion-webui
February 24, 2023 - Basically it's just a pytorch problem. There might be something that the stable-diffusion-webui devs can do, but I ran into deadends trying to just get the installer to see and use my other python versions. Be on current Fedora or other system with newer versions of python.
Author   AUTOMATIC1111
Top answer
1 of 2
8

You need to reinstall the Python interpreter itself:

sudo rpm -Uvh https://dl.fedoraproject.org/pub/fedora/linux/updates/39/Everything/x86_64/Packages/p/python3-3.12.2-2.fc39.x86_64.rpm \
              https://dl.fedoraproject.org/pub/fedora/linux/updates/39/Everything/x86_64/Packages/p/python3-libs-3.12.2-2.fc39.x86_64.rpm

For future reference, everything under /usr (apart from /usr/local) belongs to the package manager; you mustn’t delete or change files there yourself. If you want to remove Python 3, run

sudo dnf remove python3

This will tell you why you shouldn’t try this, and give you the options to add in order to proceed.

2 of 2
0
$ sudo rpm --reinstall --verbose --hash https://kojipkgs.fedoraproject.org/packages/python3.12/3.12.2/2.fc39/x86_64/python3-3.12.2-2.fc39.x86_64.rpm
Retrieving https://kojipkgs.fedoraproject.org/packages/python3.12/3.12.2/2.fc39/x86_64/python3-3.12.2-2.fc39.x86_64.rpm
Verifying... ################################# [100%]
Preparing... ################################# [100%]
Updating / installing...
1:python3-3.12.2-2.fc39 ################################# [ 50%]
Cleaning up / removing...
2:python3-3.12.2-2.fc39 ################################# [100%]

$ rpm --query python3
python3-3.12.2-2.fc39.x86_64

$ dnf --version
4.19.0
Installed: dnf-0:4.19.0-1.fc39.noarch at Mon 11 Mar 2024 07:38:12 AM GMT
Built : Fedora Project at Tue 20 Feb 2024 02:19:51 PM GMT
Installed: rpm-0:4.19.1.1-1.fc39.x86_64 at Wed 21 Feb 2024 07:00:46 PM GMT
Built : Fedora Project at Wed 07 Feb 2024 04:05:57 PM GMT

References

🌐
Linux.org
linux.org › home › forums › general linux forums › getting started
Python on Linux - Install/uninstall/reinstall | Linux.org
January 23, 2022 - TZ=Australia/NSW - Currently using: Fedora Workstation ... well shit happens... I dont have much important files on this computer however that will be good experience not to play around... still any advices? ... well shit happens... I dont have much important files on this computer however that will be good experience not to play around... still any advices? Click to expand... just reinstall the python3 version you uninstalled
🌐
Super User
superuser.com › questions › 1019943 › why-does-dnf-uninstall-python-pip-want-to-uninstall-fedora
Why does dnf uninstall python-pip want to uninstall Fedora? - Super User
If you do, the problem isn't python-pip, and you'll have to narrow down what package is providing too many things. ... Just so no-one spends too much time trying to make this work and asking me questions, I wiped my install after some (hopefully unrelated) issues I was having with Fedora.
Top answer
1 of 5
41

The following commands will remove your make altinstall-ed python:

rm -f /usr/local/bin/python2.7
rm -f /usr/local/bin/pip2.7
rm -f /usr/local/bin/pydoc
rm -rf /usr/local/include/python2.7
rm -f /usr/local/lib/libpython2.7.a
rm -rf /usr/local/lib/python2.7

You might also have to do

rm -f /usr/local/share/man/python2.7.1
rm -rf /usr/local/lib/pkgconfig
rm -f /usr/local/bin/idle
rm -f /usr/local/bin/easy_install-2.7

Although make altinstall has served me well if the "system python" has a different major.minor number from the one you install, it doesn't work that well if only the micro number (the third position) differs. That number is excluded from the installed binary, and you end up with two versions pythonX.Y. This was always a problem but once distributions started shipping with system utilities based on 2.7.X this problem has been more severe as 2.7 is supposed to be the last of the Python2 series.

IMO the best approach to solve this problem is to prevent it from becoming one: configure python to install in a directory not used by any other python. On my system they go under /opt/python/X.Y.Z.

To use any of the Pythons installed there you use [virualenv][1] to make a new environment:

virtualenv --python=/opt/python/2.7.9/bin/python2.7 venv
source venv/bin/activate

or use [virtualenvwrapper][2]. I have some aliases for the latest versions in the series I work with.

If you are using tox for testing against multiple versions (you should) the following alias will help it find the various version:

alias tox='PATH=/opt/python/2.7.9/bin:/opt/python/2.6.9/bin:/opt/python/3.4.3/bin:/opt/python/3.3.6/bin:/opt/python/3.5-dev/bin:$PATH tox'

(these are currently the latest versions, I use a slightly different setup by maintaining links from /opt/python/2.7 to the latest /opt/python/2.7.9, and for the other minor numbers as well, within the process for downloading, building and installing a new python version)

These installs are never used directly. They are always used as the basis for virtualenv environments only, hence I don't care that they are not in my normal PATH.

2 of 5
37

Starting from @Anthon's rm list, and applying @bin-s advice to search for newer files, i came up with this bash-script to completely wipe-out my Python-3.6.6 (which had been installed from sources with make altinstall):

prefix='/usr/local/'
pyver='3.6'

rm -rf \
    $HOME/.local/lib/Python${pyver} \
    ${prefix}bin/python${pyver} \
    ${prefix}bin/python${pyver}-config \
    ${prefix}bin/pip${pyver} \
    ${prefix}bin/pydoc \
    ${prefix}bin/include/python${pyver} \
    ${prefix}lib/libpython${pyver}.a \
    ${prefix}lib/python${pyver} \
    ${prefix}lib/pkgconfig/python-${pyver}.pc \
    ${prefix}lib/libpython${pyver}m.a \
    ${prefix}bin/python${pyver}m \
    ${prefix}bin/2to3-${pyver} \
    ${prefix}bin/python${pyver}m-config \
    ${prefix}bin/idle${pyver} \
    ${prefix}bin/pydoc${pyver} \
    ${prefix}bin/pyvenv-${pyver} \
    ${prefix}share/man/man1/python${pyver}.1 \
    ${prefix}include/python${pyver}m
rm -rI ${prefix}bin/pydoc ## WARN: skip if other pythons in local exist.

Use it with care (e.g. add -I option in rm command, to verify each kill).

🌐
Fedora Discussion
discussion.fedoraproject.org › ask fedora
Migrate packages to Python 3.13 on F41 - Fedora Discussion
November 16, 2024 - Trying to follow these instructions but didn’t work. python3.12 -m pip uninstall $(python3.12 -m pip list --user | cut -d" " -f1) Usage: /usr/bin/python3.12 -m pip uninstall [options] <package> ... /usr/bin/python3.12 -m pip uninstall [options] -r <requirements file> ... no such option: -…
🌐
Fedora Discussion
discussion.fedoraproject.org › ask fedora
I've mixed the pypi.org and Fedora repo Python packages — how to wipe all of the former? - Fedora Discussion
May 15, 2021 - My Python installation is close to being entirely borked, I haven’t been able to update my packages in months nor can I essentially install new ones. I’ve understood that there’s no easy way to list only the packages installed from the package index and the pip list command seems to output ...