2

I installed Ubuntu via Virtual Machine and Python3 was pre-installed. I wanted to try out a package that was made in Python2, so I installed Python 2.7 (which became the default Python) and Anaconda2.

Now that I'm done with the package, I removed anaconda2 and I want to remove Python2, too, but I am afraid it will ruin my system if it is the default one. How do I do it in a safe way?

(base) me@me-VirtualBox:~$ whereis python
python: /usr/bin/python3.6m /usr/bin/python3.6 /usr/bin/python2.7-config /usr/bin/python /usr/bin/python2.7 /usr/lib/python3.7 /usr/lib/python3.6 /usr/lib/python3.8 /usr/lib/python2.7 /etc/python3.6 /etc/python /etc/python2.7 /usr/local/lib/python3.6 /usr/local/lib/python2.7 /usr/include/python3.6m /usr/include/python2.7 /usr/share/python /usr/share/man/man1/python.1.gz
(base) me@me-VirtualBox:~$ which python
/usr/bin/python

1 Answer 1

4

You can use:

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 1

to set it as the default, without removing python2.7

this will point the command python to use /usr/bin/python3.6

or if update-alternatives --list python shows more than one result, you can interactively choose which version to use with::

update-alternatives --config python
Sign up to request clarification or add additional context in comments.

2 Comments

The first command gives me the error: "update-alternatives: error: error creating symbolic link '/etc/alternatives/python.dpkg-tmp': Permission denied". When typing "update-alternatives --list python", I get the error "no alternatives for python".
I updated my answer. please try with sudo in front as root permissions are needed for such a change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.