How I do:
Copy# Remove python2
sudo apt purge -y python2.7-minimal
# You already have Python3 but
# don't care about the version
sudo ln -s /usr/bin/python3 /usr/bin/python
# Same for pip
sudo apt install -y python3-pip
sudo ln -s /usr/bin/pip3 /usr/bin/pip
# Confirm the new version of Python: 3
python --version
Answer from BntMrx on Stack OverflowHow I do:
Copy# Remove python2
sudo apt purge -y python2.7-minimal
# You already have Python3 but
# don't care about the version
sudo ln -s /usr/bin/python3 /usr/bin/python
# Same for pip
sudo apt install -y python3-pip
sudo ln -s /usr/bin/pip3 /usr/bin/pip
# Confirm the new version of Python: 3
python --version
caution : It is not recommended to remove the default Python from Ubuntu, it may cause GDM(Graphical Display Manager, that provide graphical login capabilities) failed.
To completely uninstall Python2.x.x and everything depends on it. use this command:
Copysudo apt purge python2.x-minimal
As there are still a lot of packages that depend on Python2.x.x. So you should have a close look at the packages that apt wants to remove before you let it proceed.
Thanks, I hope it will be helpful for you.
But, it removes a lot of things that is important to me. Is there a way to install Python 3 without all the hassle? I want it so I can learn Python 3.
Edit: I have solved my problem, thank you for your efforts!
I suggest NOT messing with removing Python unless you really know what you are doing.
18.04 includes python3 - it is called.... python3 so you can have both 2.7 and 3.0 installed with No hassle..
So you may be going about this the totally wrong way.
Good Luck.
Don't try to remove any Python version. Also, chances are Python 3 is already installed and you don't have to do anything. To find out, run this:
$ whereis python | grep python3 && echo "Yes, Python 3 is present"
To access Python 3, use an example like this:
$ python3 -V
Python 3.8.2
IOW specify the desired Python version in your scripts and the command line.
software installation - uninstall Python installed by compiling source? - Unix & Linux Stack Exchange
python3 - How do I uninstall Python 2 from Ubuntu? - Unix & Linux Stack Exchange
Removing Python 2.7
Can I safely remove Python 2.7.17
Videos
Before proceeding make sure that you do not really have packages which depend on Python 2.
Then you need to install special package which set aliases for you:
sudo apt-get install python-is-python3
And optionally remove all trails of Python 2 packages manually by
sudo apt-get autoremove --purge
As user 'N0rbert' answered, you should install 'python-is-python3' to set aliases. And then check the packages that depend on python2 before removing them.
As with my experience with ubuntu 20.04 LTS, only python3 was installed, and I installed python2 by mistake. So, it was relatively easy to uninstall python2.
To uninstall, enter following commands in terminal:
sudo apt remove python2 --simulate
sudo apt remove python2
sudo apt autoremove --purge
Break-down of above commands:
sudo apt remove python2 --simulate: perform a simulation of events that would occur but do not actually change the system.
This would print details of what might happen if you remove python2 from the system.
If you are satisfied with the result(outcome) then you may do actual remove by:
sudo apt remove python2 and then sudo apt autoremove --purge to remove the configuration files and the unused packages.
Hope it helps you.
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).
You can't.
From the Ubuntu wiki / Python:
Longer term plans (e.g. 14.04)
Move Python 2 to universe, port all Python applications in main to Python 3. We will never fully get rid of Python 2.7, but since there will also never be a Python 2.8, and Python 2.7 will be nearly 4 years old by the time of the 14.04 LTS release, it is time to relegate Python 2 to universe.
This means that a lot of base packages have hard dependencies on 2.7 and it will still take a lot of time tot get things migrated. Note that Python 3 has numerous backwards incompatible changes -- it's not a regular package upgrade.
If you really want to get rid of Python 2.7, you'll have to wait for the 14.04 release, but there's no guarantee.
Came here in 2019 because I develop in Python3 by default and came to the same conclusion as OP after seeing what'd be removed after running apt purge python
Since what I really wanted was to call Python3 with just python, I ran
sudo rm /usr/bin/python
sudo ln -s /usr/bin/python3 /usr/bin/python
This way, if Python2.7 is still needed, it can be called explicitly with python2.7 while simply calling python will default to Python3 because of the symbolic link.
I don't have any bash level scripts that call python2.7 with python so this change wouldn't be disruptive - while other systems would need their scripts adjusted accordingly if they did.
The main barrier to a distribution switching the python command from python2 to python3 isn't breakage within the distribution, but instead breakage of private third party scripts developed by sysadmins and other users.
- The "python" Command On Unix-Like Systems
This answer isn't a direct response to OP, but as someone who had a similar question this is the functionality I was looking for when I was thinking of removing 2.7. Rather than delete, just prioritize which one gets to use python.
By default in latest Ubuntu release python and python3 are already included and if you completely remove python 2.7 it may break your system type in terminal
python3
to open python 3 interpreter and when you run your scripts type
python3 Scriptname
and if not already included type in terminal
sudo apt-get update && sudo apt-get install python3
have fun :)
I am not sure how the python2.7 be installed, because it was not me who did it. And i am totally new in Linux, so I really not sure what should I do...
First, to check if YOU have manually installated python2.7, do
apt show python2.7
Within all this infos there's a line APT-Manual-Installed: no. If this is NO you shouldn't probably uninstall it! For all packages, this rule is often true.
So, as said it isn't wise removing python2.7.
I suggest to add simply an alias to your bash's configuration file, so when you'll write python in your terminal, it will be like writing python3.
This is useful, but potentially can create misunderstanding.
HOW TO DO
Add
alias python=python3
at the bottom of ~/.bashrc file (or simply echo "alias python=python3" >> ~/.bashrc)
Than do:
source ~/.bashrc
from the terminal to update bash with the changes.
There is no need to remove python 2.7.16, you could install both versions side by side.
Then you can choose which one is the default that is executed with python using update-alternatives, as shown here.
You could always run explicitly python3 as mentioned by ICE_Plane, but it would not work with scripts, etc., which invoke python.
Actually, you probably wouldn't want to remove python 2.7.16, see Is it safe to remove Python 2.7.15rc1 from Ubuntu 18.04?
use python3 and it runs with python 3
I would like to remove python2.7 from my system but not sure how to tell that nothing is still using it.
These are the binaries currently in my path:
python2
python2.7
python3
python3.10
python3.10-config
python3-config
While reinstalling Ubuntu is probably the easiest way, it's worth pointing out that it's possible to recover without reinstalling everything.
To do this, manually download the python2.7 package (and its dependencies), and manually install them using dpkg (bypassing APT, which requires Python). Once that's installed, apt should work again, and so apt-get install ubuntu-desktop will restore your system. (If apt-get still doesn't work, you might also need to download and install any missing dependencies.)
In the future, if you need to reinstall a package, instead use
sudo apt-get install --reinstall python2.7
or
sudo aptitude reinstall python2.7
which reinstalls the package without having to remove the dependencies.
Removing Python is not a good idea as much of Ubuntu depends on it. You may have seen a warning telling you which packages depend on python and thus will be removed with Python. When proceeding you end up with a quite stripped down OS.
Reinstalling Ubuntu would now be the easiest and safest way to get it back. Take care not to delete your HOME when you do so.
Cloudron does automatic security updates.