Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check all the installed Python versions on Windows?

Tags:

python

windows

Please note I'm not asking "how to check which version of Python did I install".

I've installed several versions of Pythons on my Windows computer, for example Python 2.7-64, Python 2.7-32, and Python 3.7-32.

Python 3 includes "py" and "pyw" which helps me to easily start different Pythons, for example:

  • "py -2.7" starts Python 2.7-64
  • "py -2.7-32" starts Python 2.7-32
  • "py -3.7-32" starts Python 3.7-32

What I'm wondering is, how to check how many different versions of Python did I install on my Windows PC and what versions are they?

PyCharm is able to find it but, for one thing, I don't know if it is a complete list, and for another, I wonder if there is any tool provided by Python or the operating system can do it.

like image 967
Vespene Gas Avatar asked Nov 15 '18 04:11

Vespene Gas


People also ask

How many versions of Python do I have installed?

Check Python version on the command line: --version , -V , -VV. Execute the python or python3 command with the --version or -V option on the command prompt ( cmd ) on Windows or the terminal on Mac and Linux.

How can I tell what version of Python is installed on Windows?

On your Windows PC where you've installed Python, use the PC's built-in PowerShell utility to check the version number. To start, open your “Start” menu and search for “Windows PowerShell” (without quotes). Then click the utility in the search results. PowerShell will display the version of Python installed on your PC.

How do I tell which version of Python is installed?

Check Python Version: Script This is especially useful when you have multiple Python versions installed on your computer. 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.


2 Answers

I just got the answer. By typing "py -h" or "py --help" I got the help message:

C:\Users\admin>py -h
Python Launcher for Windows Version 3.7.1150.1013

usage:
py [launcher-args] [python-args] script [script-args]

Launcher arguments:

-2     : Launch the latest Python 2.x version
-3     : Launch the latest Python 3.x version
-X.Y   : Launch the specified Python version
     The above all default to 64 bit if a matching 64 bit python is present.
-X.Y-32: Launch the specified 32bit Python version
-X-32  : Launch the latest 32bit Python X version
-X.Y-64: Launch the specified 64bit Python version
-X-64  : Launch the latest 64bit Python X version
-0  --list       : List the available pythons
-0p --list-paths : List with paths

Which tells me that "-0" (zero, not letter "O") lists the available pythons:

C:\Users\admin>py -0
Installed Pythons found by py Launcher for Windows
 -3.7-64 *
 -3.7-32
 -2.7-64
 -2.7-32

While "-0p" lists not only the versions, but also the paths:

C:\Users\admin>py -0p
Installed Pythons found by py Launcher for Windows
 -3.7-64        C:\Users\admin\AppData\Local\Programs\Python\Python37\python.exe *
 -3.7-32        C:\Users\admin\AppData\Local\Programs\Python\Python37-32\python.exe
 -2.7-64        C:\Python27_64\python.exe
 -2.7-32        C:\Python27_32\python.exe
like image 69
Vespene Gas Avatar answered Oct 08 '22 11:10

Vespene Gas


If py -0p doesn't work for you:

Solution

PowerShell: C:\> dir site.py -s -ErrorAction SilentlyContinue CMD: C:\>dir site.py /s

Citation

I found this workaround on Webucator and made some small adjustments for powershell.

Explanation

dir with the s parameter "lists every occurrence of the specified file name within the specified directory and all subdirectories" (Microsoft Docs).

Since dir <filename> /s returns occurrences of <filename> within the specified directory and all sub-directories, run this from your C drive (unless you only want to check under a specific directory, e.g. check Python installations for a user).

dir site.py /s technically just checks for all site.py files (which is a module in Python's Standard Library) and returns their parent directory's full path. This means that it will miss an installation if site.py has been removed for some reason and also return directories that aren't Python installations but contain python files named site.

Lastly, this returns the parent directory for site.py, not the path for the Python installation's executable (like py -0p would if it worked for you). site.py's parent directory will include the path to the Python installation (e.g. C:\Users\Name\Python36) as well as the additional sub-driectories containing site.py (e.g. \Lib\).

like image 7
sandeman_13 Avatar answered Oct 08 '22 12:10

sandeman_13