How can I find out what versions of Python I have?
I am using Ubuntu 14.04 (Trusty Tahr).
Best Answer
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:
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:
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:
I think by default Python 2.7 will be used (i.e. is symlinked to /usr/bin/python). You can change this by changing that symlink. Most Python programs will specify which version they need and use it automatically.
Changing the symlink is not advised, as it is likely to cause programs to return errors.
It is fair to assume that package python-reportlab is the 2.7 version and package python3-reportlab is the python 3.x version. If however you want to check that further you can use dpkg -L python-reportlab — this will list the package contents and you will see that the files are in /usr/lib/python2.7.
Unfortunately the dpkg -L works only on installed packages so if you want to check it before you install the package you will have to use the Ubuntu packages web interface. Once you open a package details page you can click on list of files and find out whether the files are in /usr/lib/python2.7 or in /usr/lib/python3.
Best Answer
You can use
python -V
(et al.) to show you the version of Python that thepython
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:
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: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:It's obviously a pretty hideous command but this is again real output and it seems to have done a fairly thorough job.