Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to choose which version of python runs from terminal?

Tags:

python

unix

I have a few different versions of python on my computer. How do I choose which one is run from my terminal when I type "python" into the prompt?

like image 989
mjmostachetti Avatar asked Mar 30 '14 01:03

mjmostachetti


People also ask

How do I know which version of Python I am using?

To check which Python version is running, you can use either the sys or the platform module. The script will be the same for Windows, macOS, and Linux. Of course, you can easily obtain the individual components of this tuple using an index (e.g. sys. version_info[0] ) or a name (e.g. sys.


1 Answers

Use which to see where your python command resides. Then use ls -l to find out where it really is. Then link the one you want instead. Note that the other installed versions are usually all available by their respective names.

$ which python
/usr/bin/python
$ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 9 Jun 18  2013 /usr/bin/python -> python2.7
$ ls /usr/bin/python*
/usr/bin/python   /usr/bin/python2.7         /usr/bin/python2-config
/usr/bin/python2  /usr/bin/python2.7-config  /usr/bin/python-config
$ sudo ln -sf /usr/bin/python2 /usr/bin/python

Note that this changes which Python version all programs for all users on your computer will probably use! If you only want to change it for yourself. You can alias it by adding a alias python='/usr/bin/python2' line (with python2 replaced by the version you want) to ~/.bashrc in linux or ~/.bash_profile in Mac. (You'll need to restart your terminal session in this case.)

like image 179
Pi Marillion Avatar answered Sep 24 '22 16:09

Pi Marillion