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?
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.
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.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With