How to check all versions of python installed on osx and centos

PythonLinuxMacosCentosVersion

Python Problem Overview


I just started setting up a centos server today and noticed that the default version of python on centos is set to 2.6.6. I want to use python 2.7 instead. I googled around and found that 2.6.6 is used by system tools such as YUM so I should not tamper with it. Then I opened up a terminal on my mac and found that I had python 2.6.8 and 2.7.5 and 3.3.3 installed. Sorry for the long story. In short I just want to know how to lookup all the version of python installed on centos so I don't accidentally install it twice.

Python Solutions


Solution 1 - Python

The more easy way its by executing the next command:

ls -ls /usr/bin/python*

Output look like this:

/usr/bin/python           /usr/bin/python2.7        /usr/bin/pythonw
/usr/bin/python-config    /usr/bin/python2.7-config /usr/bin/pythonw2.7

Solution 2 - Python

we can directly use this to see all the pythons installed both by current user and the root by the following: whereis python

Solution 3 - Python

Find out which version of Python is installed by issuing the command python --version: $ python --version Python 2.7.10

If you see something like this, Python 2.7 is your default version. You can also see if you have Python 3 installed:

$ python3 --version
Python 3.7.2

If you also want to know the path where it is installed, you can issue the command "which" with python and python3:

$ which python
/usr/bin/python

$ which python3
/usr/local/bin/python3

Solution 4 - Python

Here is a cleaner way to show them (technically without symbolic links). This includes python2 and python3 installs:

ls -1 /usr/bin/python* | grep '.*[2-3]\(.[0-9]\+\)\?$'

Where grep filters the output of ls that that has that numeric pattern at the end ($).

Or using find:

find /usr/bin/python* ! -type l

Which shows all the different (!) of symbolic link type (-type l).

Solution 5 - Python

Use,

yum list installed
command to find the packages you installed.

Solution 6 - Python

As someone mentioned in a comment, you can use which python if it is supported by CentOS. Another command that could work is whereis python. In the event neither of these work, you can start the Python interpreter, and it will show you the version, or you could look in /usr/bin for the Python files (python, python3 etc).

Solution 7 - Python

COMMAND: python --version && python3 --version

OUTPUT:

> Python 2.7.10
> Python 3.7.1

ALIAS COMMAND: pyver

OUTPUT:

> Python 2.7.10
> Python 3.7.1

You can make an alias like "pyver" in your .bashrc file or else using a text accelerator like AText maybe.

Solution 8 - Python

It depends on your default version of python setup. You can query by Python Version:

python3 --version //to check which version of python3 is installed on your computer
python2 --version // to check which version of python2 is installed on your computer
python --version // it shows your default Python installed version.

Solution 9 - Python

ls -l /usr/bin/python* & ls -l /usr/local/bin/python*

Solution 10 - Python

compgen -c python | grep -P '^python\d'

This lists some other python things too, But hey, You can identify all python versions among them.

Solution 11 - Python

Sift through the output of this script.

sudo find / -name 'python*' -type f  -exec du -h {}  + | sort -r -h ~/Documents/python_locations.txt

Solution 12 - Python

I would add to @nurealam siddiq answer,

python --version // it shows your default Python installed version.

python2 --version // to check which version of python2 is installed 

python3 --version //to check which version of python3 is installed 

python3.X --version // to further check which python3.X is installed

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionhchView Question on Stackoverflow
Solution 1 - PythonGabriel CaceresView Answer on Stackoverflow
Solution 2 - PythonKe LiView Answer on Stackoverflow
Solution 3 - PythonKPandianView Answer on Stackoverflow
Solution 4 - PythondanbrosView Answer on Stackoverflow
Solution 5 - PythonlpsandaruwanView Answer on Stackoverflow
Solution 6 - Pythonjm13fireView Answer on Stackoverflow
Solution 7 - PythonAlan O'MearaView Answer on Stackoverflow
Solution 8 - Pythonnurealam siddiqView Answer on Stackoverflow
Solution 9 - Pythongeorge manoView Answer on Stackoverflow
Solution 10 - PythonAppaji ChintimiView Answer on Stackoverflow
Solution 11 - PythontsmView Answer on Stackoverflow
Solution 12 - PythonSinghView Answer on Stackoverflow