Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How can I find out what versions of Python I have?

I am using Ubuntu 14.04 (Trusty Tahr).

share|improve this question
Also, a quick way to see what python binaries are installed is : ls /usr/bin | grep python – Tejas Kale Aug 1 '14 at 13:06
up vote 35 down vote accepted

You can use python -V (et al.) to show you the version of Python that the python command resolves to. If that's all you need, you're done. But to see every version of python in your system takes a bit more.

In Ubuntu we can check the resolution with readlink -f $(which python). In default cases in 14.04 this will simply point to /usr/bin/python2.7.

We can chain this in to show the version of that version of Python:

$ readlink -f $(which python) | xargs -I % sh -c 'echo -n "%: "; % -V'
/usr/bin/python2.7: Python 2.7.6

But this is still only telling us what our current python resolution is. If we were in a Virtualenv (a common Python stack management system) python might resolve to a different version:

$ readlink -f $(which python) | xargs -I % sh -c 'echo -n "%: "; % -V'
/home/oli/venv/bin/python: Python 2.7.4

This is real output.

The fact is there could be hundreds of different versions of Python secreted around your system, either on paths that are contextually added, or living under different binary names (like python3).

If we assume that a Python binary is always going to be called python<something> and be a binary file, we can just search the entire system for files that match those criteria:

$ sudo find / -type f -executable -iname 'python*' -exec file -i '{}' \; | awk -F: '/x-executable; charset=binary/ {print $1}' | xargs readlink -f | sort -u | xargs -I % sh -c 'echo -n "%: "; % -V'
/home/oli/venv/bin/python: Python 2.7.4
/media/ned/websites/venvold/bin/python: Python 2.7.4
/srv/chroot/precise_i386/usr/bin/python2.7: Python 2.7.3
/srv/chroot/trusty_i386/usr/bin/python2.7: Python 2.7.6
/srv/chroot/trusty_i386/usr/bin/python3.4: Python 3.4.0
/srv/chroot/trusty_i386/usr/bin/python3.4m: Python 3.4.0
/usr/bin/python2.7: Python 2.7.6
/usr/bin/python2.7-dbg: Python 2.7.6
/usr/bin/python3.4: Python 3.4.0
/usr/bin/python3.4dm: Python 3.4.0
/usr/bin/python3.4m: Python 3.4.0
/web/venvold/bin/python: Python 2.7.4

It's obviously a pretty hideous command but this is again real output and it seems to have done a fairly thorough job.

share|improve this answer

Type following in the terminal (Ctrl+Alt+T):

python -V


python --version

You can find a list of options/parameters for many commands in the terminal by typing the command followed by --help


python --help

Manual/manpages also available for most of such CLI which can be displayed by man <command> (Ex: man python)

From man python:

        -V ,  --version
              Prints the Python version number of the executable and exits.

There is also python3 installed on many machines, so you can do:

python3 --version

to find out what python 3.x you are running.

share|improve this answer
It's worth noting, as @Florian Diesch below alludes to that you likely have multiple versions of "python". The default "python" call points to an installation of python 2.7, though ubuntu 14.04 comes with python 3.0 as well. – Mitch Aug 1 '14 at 12:01
python --version


python2 --version

show the version of Python 2.x,

python3 --version

the installed version of Python 3.x

share|improve this answer

When you run python in the terminal, it will produce output like this:

Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

See the first line - Python 2.7.6.

Also run python3. I have 3.4.1

Python 3.4.1 (default, Jul 31 2014, 12:46:17) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.

However, this won't show you them all. If you have 2 or more python 3.X.x versions, you will only see the latest one.

By default on 14.04, you have 2.7.6 and 3.4.0. As you can see, I have updated to 3.4.1. I know that I still have 3.4.0 because when I go to /usr/bin I see python3.4, and if I run /usr/bin/python3.4 in the command line, I get 3.4.0, and running /usr/local/bin/python3.4 gives me 3.4.1

share|improve this answer
"If you have 2 or more python 3.X.x versions, you will only see the latest one." Won't it instead show whichever one has its containing directory listed first in the PATH environment variable? Why would running python3 always run the highest (sub)version of python3 that is installed? Or, in practice, won't it show whatever version the /usr/bin/python3 symbolic link points to, which need not be the latest? – Eliah Kagan Jul 31 '14 at 18:43
@Eliah No idea, but some programs take it from there and others from the /usr/bin one... – Tim Jul 31 '14 at 18:45
Well, when it comes to actually running python programs, depending on how they are run, the hashbang line may be used to determine which python acts as the interpreter (details; also note the use of env in hashbang lines to find whichever interpreted may be system-preferred in common in Python scripts). I'm not sure if that's what you mean by differences between some programs and others. – Eliah Kagan Jul 31 '14 at 18:50
No, a user said that idle ran with 3.4.0 and command line with 3.4.1... – Tim Jul 31 '14 at 18:55

You can also check Python version from code itself using platform module from standard library. There are two functions: platform.python_version() (returns string) and platform.python_version_tuple() (returns tuple). Script:

import platform



$ python 
('3', '4', '1')
$ python2.7 
('2', '7', '8')
share|improve this answer
I think it's more common to use sys.version or sys.version_info. – Matt Nordhoff Aug 2 '14 at 16:31

Easily, open the terminal and do the following:



to verify your 2.x version In my case, it will appear:

Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

For the 3.x, write:


In my case, it appears:

Python 3.4.0 (default, Apr 11 2014, 13:05:11) 
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.

For both cases, to get out from Python shell, write:

share|improve this answer
  • In shell terminal

    $ which -a python lists all your python.

    $ which -a python2.7 lists all your python2.7.

    $ /usr/bin/python -V gives information about the version of /usr/bin/python.

  • check in python script

here is an ilustration in ipython shell:

In [1]: import sys

In [2]: sys.version
2.7.11 |Anaconda 2.5.0 (64-bit)| (default, Dec  6 2015, 18:08:32) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)]

In [3]: sys.version_info
sys.version_info(major=2, minor=7, micro=11, releaselevel='final', serial=0)

In [4]: sys.version_info >= (2,7)
Out[4]: True

In [5]: sys.version_info >= (3,)
Out[5]: False
share|improve this answer

protected by Community Nov 19 '14 at 8:24

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.