0

I need to remove python 2.7.16 but even If I use: sudo apt-get purge python2.7 doing python --version still prints Python 2.7.16 I need to have python 3.6+. plz help

  • Have you considered using a tool like pyenv? – Seamus May 19 '21 at 19:06
  • 2
    What version Ubuntu are you running? Python 2.7 might be necessary for some of them for system scripts. Did you install, or do you already have python-3 (they may be installed and run separately, just don't change the system default or you will break things). Make a local change like adding an alias for python to the one you want. – ubfan1 May 19 '21 at 19:10
  • 2
    Ubuntu is using python for a lot of stuff. If you remove a version needed by your (un-specified) Ununtu release, you will break your system badly. – Soren A May 19 '21 at 19:18
  • Are you sure that you do not already have a version python 3? Run the command "Which python3" or "python3 --version". To use python 2, the command is "python", whereas to use python 3, the command is python3. – Eagle_Mike May 19 '21 at 19:26
  • We don't know your OS & release details; so can't know if python2 is installed by default, you've installed it, or its necessary. You've tagged debian packaging (shared between Ubuntu and Debian), so how does that apply to your question? – guiverc May 19 '21 at 22:33

3 Answers3

2

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?

1

use python3 and it runs with python 3

0

Starting with the Debian 11 (bullseye) and Ubuntu 20.04 LTS (focal) releases use

sudo apt install python-is-python3