- What version of Python do I have?
- 9 Answers 9
- How to Check all the Python Versions Installed on Linux
- How to Check all the Python Versions Installed on Linux
- Method 1: Using whereis command
- Method 2: Using ls command
- Method 3: Using compgen command
- Method 4: Using find command
- How to Check All Python Versions Installed on Windows: A Step-by-Step Guide
- Using the Command Prompt or PowerShell to Find All Installed Python Versions
- Checking the Python Version on Windows, Mac, or Linux
- How can I check all the installed Python versions on Windows?
- Locating the Installation Path for Python
- Running Multiple Versions of Python on Windows
- Uninstalling and Installing Python Versions
What version of Python do I have?
@TejasKale Better to run ls /usr/bin/python* (or ls /usr/bin/*python* if you really want files with python anywhere in the name). That way, ls still formats its output for a terminal (and you get multiple columns and, with the default ls alias in Ubuntu, colorization).
9 Answers 9
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
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 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/ ' | 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.
How to Check all the Python Versions Installed on Linux
In this article, we will see how to check all the python versions installed on a Linux system. Many times you might have noticed that either knowingly or unknowingly you end up installed multiple python versions in your linux system. And some day you only realize this when you started getting certain strange messages on the output pointing different versions of python available in the System. Well, at that point of time you probably would like to know all the python versions installed on your System. While there are many ways to check this but here we will only see four methods that can be used in a linux system to detect all the python versions.
How to Check all the Python Versions Installed on Linux
Method 1: Using whereis command
The first method you can think of using is through whereis command which is easily available in almost all the linux distributions. So if you are looking for all the versions of python3 then you just need to run whereis python3 command and you will able to see all the python3 versions as shown below. This works great in almost all the linux systems.
cyberithub@ubuntu:~$ whereis python3 python3: /usr/bin/python3 /usr/bin/python3.8 /usr/bin/python3.9 /usr/lib/python3 /usr/lib/python3.8 /usr/lib/python3.9 /etc/python3 /etc/python3.8 /etc/python3.9 /usr/local/lib/python3.8 /usr/local/lib/python3.9 /usr/include/python3.8 /usr/share/python3 /usr/share/man/man1/python3.1.gz
Similarly, if you would like to check all the installed versions of python2 then you need to use whereis python2 command as shown below.
cyberithub@ubuntu:~$ whereis python2 python2: /usr/bin/python2.7 /usr/bin/python2 /usr/lib/python2.7 /etc/python2.7 /usr/local/lib/python2.7 /usr/share/man/man1/python2.1.gz
Method 2: Using ls command
The second method that I always love to use is through ls command. This command is also very easily available on almost all the linux distribution. Using this command, you just need to look for all the python binaries available under /usr/bin path to detect all the versions of python currently installed as shown below. You can check more about ls command on 16 Best ls command examples in Linux.
cyberithub@ubuntu:~$ ls -ls /usr/bin/python* 0 lrwxrwxrwx 1 root root 9 Mar 13 2020 /usr/bin/python2 -> python2.7 3580 -rwxr-xr-x 1 root root 3662032 Jul 1 2022 /usr/bin/python2.7 0 lrwxrwxrwx 1 root root 9 Nov 15 20:46 /usr/bin/python3 -> python3.8 5368 -rwxr-xr-x 1 root root 5494584 Nov 14 18:29 /usr/bin/python3.8 5668 -rwxr-xr-x 1 root root 5803968 Nov 23 2021 /usr/bin/python3.9 4 -rwxr-xr-x 1 root root 384 Mar 28 2020 /usr/bin/python3-futurize 4 -rwxr-xr-x 1 root root 388 Mar 28 2020 /usr/bin/python3-pasteurize
Method 3: Using compgen command
Another method that you can think of using is through compgen command. If this utility is available in your system then you need to simply run compgen -c python | grep -P ‘^python\d’ command to list out all the versions of python installed in the system.
cyberithub@ubuntu:~$ compgen -c python | grep -P '^python\d' python3-pasteurize python2.7 python2 python3 python3.8 python3-futurize python3.9 python3-pasteurize python2.7 python2 python3 python3.8 python3-futurize python3.9
Method 4: Using find command
The last method that I would advise to use is through find command. You can search and look for all different python symbolic link under /usr/bin path using find /usr/bin/python* ! -type l command as shown below. You can check more about find command on 40 Best Examples of Find Command in Linux.
cyberithub@ubuntu:~$ find /usr/bin/python* ! -type l /usr/bin/python2.7 /usr/bin/python3.8 /usr/bin/python3.9 /usr/bin/python3-futurize /usr/bin/python3-pasteurize
How to Check All Python Versions Installed on Windows: A Step-by-Step Guide
Learn how to check all Python versions installed on Windows with a step-by-step guide. Use command prompt or PowerShell to find all installed Python versions and locate their installation path.
Python is a popular programming language that is widely used in various fields such as web development, data analysis, and artificial intelligence. If you are a Windows user, you may have multiple Python versions installed on your system and need to verify which versions are currently installed. In this blog post, we will provide a step-by-step guide on how to check all Python versions installed on Windows and provide some helpful tips and best practices for python coding .
Using the Command Prompt or PowerShell to Find All Installed Python Versions
The easiest way to find all Installed Python Versions on your Windows system is by using the command prompt or PowerShell. Follow the steps below to check all Python versions installed on your Windows computer:
- Open the command prompt or PowerShell by pressing the Windows key + R, type “cmd” or “powershell” and then press Enter.
- Type the command “py -0” in the command prompt or PowerShell and press Enter. This command will display a list of all Python installations registered in the registry.
- The Python launcher requires interpreters to be registered in the registry for Windows. If there are no registered Python versions found, you will get an error message saying that “No installed Python distributions found”. In this case, you need to install Python on your Windows system.
Checking the Python Version on Windows, Mac, or Linux
Once you have found all the installed Python versions , you can check the Python version on your Windows, Mac, or Linux system. Follow the steps below to check the Python version:
- Open the command prompt or PowerShell by pressing the Windows key + R, type “cmd” or “powershell” and then press Enter.
- Type the command “python –version” into PowerShell on Windows, or the Terminal on Linux or Mac to check the Python version.
- The command “python –version” may not work if the Python executable is not in the system PATH. In this case, you need to add the Python executable to the system PATH.
- The version of Python can also be checked by typing “import sys; print(sys.version)” in the Python shell.
python import sys print(sys.version)
How can I check all the installed Python versions on Windows?
How can I check all the installed Python versions on Windows? [ Gift : Animated Search Duration: 1:21
Locating the Installation Path for Python
If you want to locate the installation path for Python, you can do so by following these steps:
- Open the command prompt or PowerShell by pressing the Windows key + R, type “cmd” or “powershell” and then press Enter.
- Type the command “where python” and press Enter. This will display the installation directory for Python.
- The installation path for Python can also be found in “HKCU\SOFTWARE\Python\PythonCore\versionnumber\InstallPath”.
Running Multiple Versions of Python on Windows
If you want to run multiple versions of python on your Windows computer, you can use the Python launcher. Follow the steps below to run multiple versions of Python:
- Open the command prompt or PowerShell by pressing the Windows key + R, type “cmd” or “powershell” and then press Enter.
- To run a specific version of python , use the command “py — ”.
Uninstalling and Installing Python Versions
If you want to uninstall a specific version of Python, you can do so by using the command “pyenv uninstall ”. Follow the steps below to uninstall a specific version of Python:
- Open the command prompt or PowerShell by pressing the Windows key + R, type “cmd” or “powershell” and then press Enter.
- Type the command “pyenv uninstall ” and press Enter.
- To install a new version of Python, use the command “pyenv install ”. Follow the steps below to install a new version of Python:
- Open the command prompt or PowerShell by pressing the Windows key + R, type “cmd” or “powershell” and then press Enter.
- Type the command “pyenv install ” and press Enter.
In conclusion, checking all Python versions installed on Windows is easy and can be done using the command prompt or PowerShell. There are also other methods to check the Python version, find the installation path, and run multiple versions. Python is a versatile and powerful programming language with many advantages and disadvantages. By following best practices and being aware of common issues, Python can be a great tool for many applications.