How to replace python 3 with python 2 in Linux

It depends on the application developed in Python that you are running, it can be compatible with the interpreter of python 3, python 2 or even both. In some cases we have python 3 and python 2 installed, but no matter how much we tell a tool to run with python 2, it continues to run with python 3, so the simplest solution to this problem is replace python 3 with python 2.

It is worth noting that the solution I propose to replace python 3 by python 2, affects all applications running with python, so some of your applications may not be able to run.

Replace python 3 with python 2

To replace python 3 with python 2 we must follow the following simple steps:

  • Install python 2 with sudo

  • Change the symlink created by python 3 into /usr/bin/python by python 2

cd /usr/bin
ls -l python
    lrwxrwxrwx 1 root root 7  17 Dec. 12:04 python -> python3
ln -sf python2 python
ls -l python
    lrwxrwxrwx 1 root root 10 Apr 11 14:28 python -> python2
  • Change the symbolic link created by the package virtualenv en /usr/bin/virtualenv

cd /usr/bin
ln -sf virtualenv2 virtualenv

With these simple steps you will already have python 2 as the default interpreter, in the same way, you can verify that this is so with the following command:

python --version

With information from the wiki by arch Linux


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.