4

Due to my own stupidity, I somehow set the python command to run python 3 instead of the default python 2. How do I undo this? I am on Ubuntu 18.04.

$ python -V
Python 3.7.6
$ python3 -V
Python 3.7.6
4
  • it depends on your settings may be in your editor Commented Jul 2, 2020 at 13:36
  • I don't think it's my editor. My gnome-terminal won't open because of this issue. Commented Jul 2, 2020 at 13:38
  • I think you have to either : reinstall python 2 to override the name, or change the index for "python" to point at python2. Commented Jul 2, 2020 at 13:38
  • Without knowing what you did, it is nearly impossible to tell you how to undo it, given that the way a command ends up being executed in the Unix environment has so many degrees of freedom (PATH, different shells, aliases, symlinks, ...). If you are on Ubuntu, you might be better off asking on askubunu.com, in case Ubuntu has some way of forcing things back to the as-installed state. Commented Jul 2, 2020 at 13:43

5 Answers 5

4

You can change the alias python="/usr/bin/python2.7",for example :

alias python="/usr/bin/python3.3"
python
Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 16 2013, 23:39:35) 

You can also add this line in your .bashrc file

echo "alias python=/usr/bin/python3.3" >> ~/.bashrc 
Sign up to request clarification or add additional context in comments.

1 Comment

and add the above answer codes to the ~/.bashrc file or run this command in the bash: echo "alias python=/usr/bin/python3.3" >> ~/.bashrc
4

You can list all the version of Python installed and change the default Python version Try the following commands on terminal.

$:~# update-alternatives --config python
There are 4 choices for the alternative python (providing /usr/local/bin/python).

  Selection    Path                Priority   Status
------------------------------------------------------------
  0            /usr/bin/python3     4         auto mode
  1            /usr/bin/python2.7   2         manual mode
* 2            /usr/bin/python3     4         manual mode
  3            /usr/bin/python3.7   3         manual mode
  4            /usr/bin/python3.8   4         manual mode

Press <enter> to keep the current choice[*], or type selection number: 4
update-alternatives: using /usr/bin/python3.8 to provide /usr/local/bin/python (python) in manual mode

Set the default python version using python version. Finally, you can check the success of command as below.

root@kali:~# python --version
Python 3.8.2

It should show Python 2.x in your case.

Comments

1

On most Unix-Linux systems, python is a link or a symbolic link in /usr/bin or /usr/local/bin. You should search where it is with type python and control what it is.

If it is a link or a symlink, just remove it and make it point to your installation of python 2.

Comments

0

Use type python to check what it points to, then check your .bashrc for two things:

  • whether the path from type python is somewhere included in PATH
  • whether you defined an alias for python somewhere

Comments

-3

To install python2, run:

sudo apt install python-minimal

To run python2,

python2

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.