7

When I checked Python version as normal user, it is showing Python 2:

$ python --version
Python 2.7.15rc1

And when try to run as root :

# python --version
Python 3.6.7

Any suggestion how to remove this Python 2.7

1
  • 2
    If your main goal is to call python3 when you run python, you must define aliases in .bashrc instead of removing python. Messing up python may cause your system to break.
    – Kulfy
    Mar 1, 2019 at 5:16

1 Answer 1

18

You need to define the two different python versions

sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.NN 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.NN 2

Then you need to choose which version should be defined as default

sudo update-alternatives --set python /usr/bin/python3.NN

Note! You need to check what version you have of python and replace NN with your version.

python2 --version
python3 --version
6
  • Nice to hear, can you mark it as an answer then?
    – MatsK
    Mar 2, 2019 at 16:19
  • 1
    Worked like a charm , thank you very much.
    – amolgautam
    Sep 1, 2019 at 0:53
  • but when I sudo apt install python-pip, it still installs with python2.7, not 3.
    – BMW
    Jan 20, 2020 at 0:28
  • 1
    ok, got the point, I have to use the package name for python 3 as well: sudo apt install python3-pip
    – BMW
    Jan 20, 2020 at 0:59
  • I get an error 'no alternatives for python' when I try this.
    – Bret Hess
    Nov 11, 2021 at 23:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.