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 OverflowI doubt your make install overwrote version 2.6, so unless it did this can be fixed by simply re-organizing your PATH variable
If you did ./configure without a --prefix, Python will have been installed in /usr/local by default, so you could remove it with:
rm /usr/local/bin/python
however that will leave behind all sorts of other Python-related files in /usr/local. If Python is the only thing you have installed into /usr/local, it'll be easy to wipe it all by removing /usr/local/bin/*, /usr/local/lib/* and /usr/local/include/*. Otherwise, you'd have to be careful to remove only the Python-related files. That's all part of the fun of the wonderful Unix “install everything into the same folders” strategy (and why you typically do want to specify a --prefix.)
uninstall old version python (fedora) - Stack Overflow
python in fedora
How to manage python's version?
Is there a way to downgrade python on Fedora 35?
Videos
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.)
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.)
The default python in Fedora is still python 2.x (see here). So you need to type "python3" to start the 3.x interpreter. It is not a good idea to remove python 2.x from your Fedora installation because there are likely a number of system functions that use/require python 2.x. If you really want to be able to just type "python" to run the 3.x interpreter, I recommend that you modify the .bash_login file in your home directory to make python an alias to the default python 3 interpreter in /usr/bin.
You don't, unless you want to break your system. Install the python3 package from the repositories and invoke it as python3.
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:
-
flatpak
-
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 35 introduced python 3.10 but it is incompatible with many, many packages. Dnf downgrade doesn't let you downgrade either? Why is this, seems stupid.
Kind of forces me to not use system python installation for regular use.
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.
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
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.
$ 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
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.
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).
Hi, I am a new Fedora user after switching from Ubuntu and I have a doubt about uninstalling packages, is there any command equivalent to Ubuntu's "purge"? I just want to make sure to remove everything related to the program I want to uninstall, no dependencies or config files, is sudo dnf remove enough? Or I need something else?