如何在Windows上检查所有已安装的Python版本?

Col*_*ver 8 python

请注意,我不是在问“如何检查我安装了哪个版本的Python”。

我已经在Windows计算机上安装了多个版本的Python,例如Python 2.7-64,python 2.7-32,Python 3.7-32。

Python 3包含“ py”和“ pyw”,可帮助我轻松启动不同的Python,例如:

  • “ py -2.7”启动Python 2.7-64
  • “ py -2.7-32”启动Python 2.7-32
  • “ py -3.7-32”启动Python 3.7-32

我想知道的是,如何检查我在Windows PC上安装了多少个不同版本的Python,它们是什么版本?

PyCharm可以找到它,但是,一方面,我不知道它是否完整,而另一方面,我想知道Python是否提供了任何工具,或者操作系统是否可以做到这一点。

Ond*_*nko 17

在cmd中运行:

py --list
Run Code Online (Sandbox Code Playgroud)

我的结果(安装了所有版本的python):

 -V:3.11 *        Python 3.11 (64-bit)
 -V:3.9
 -V:3.8           Python 3.8 (64-bit)
 -V:3.6           Python 3.6 (64-bit)
 -V:3.5
 -V:ContinuumAnalytics/Anaconda39-64 Anaconda py39_4.12.0
Run Code Online (Sandbox Code Playgroud)


Col*_*ver 14

我才得到答案。通过输入“ py -h”或“ py --help”,我得到了帮助消息:

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
Run Code Online (Sandbox Code Playgroud)

告诉我“ -0”(零,而不是字母“ O”)列出了可用的python:

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
Run Code Online (Sandbox Code Playgroud)

而“ -0p”不仅列出版本,而且列出路径:

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
Run Code Online (Sandbox Code Playgroud)

  • 我想这需要Python 3.7。在Python 3.6中,“ py -0”返回“未安装请求的Python版本(0)”。 (5认同)
  • 它向我显示错误“命令未找到:py”,尝试使用“python -h”,它根本没有“-0”参数。 (3认同)

小智 9

如果您使用的是 Windows,请在 CMD 中输入

where python
Run Code Online (Sandbox Code Playgroud)

并得到这样的东西

C:\Python310\python.exe
C:\Users\facundo\AppData\Local\Microsoft\WindowsApps\python.exe
C:\Users\facundo\AppData\Local\Programs\Python\Python38\python.exe
Run Code Online (Sandbox Code Playgroud)


小智 5

如果py -0p不适合您:

解决方案

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

引文

我在Webucator上找到了这个解决方法,并对powershell 做了一些小的调整。

解释

dir带有s参数“列出指定目录和所有子目录中指定文件名的每个匹配项”(Microsoft Docs)。

由于dir <filename> /s的<文件名>返回事件指定的目录和所有子目录,从你的C盘运行此(除非你只想要一个特定目录下检查,如检查的Python安装的用户)。

dir site.py /s从技术上讲,只检查所有 site.py 文件(它是 Python 标准库中的一个模块)并返回其父目录的完整路径。这意味着如果由于某种原因删除了 site.py 并且返回的目录不是 Python 安装但包含名为 site.py 的 Python 文件,它将错过安装。

最后,这将返回 site.py 的父目录,而不是 Python 安装的可执行文件的路径(py -0p如果它对你有用的话)。site.py 的父目录将包括 Python 安装路径(例如 C:\Users\Name\Python36)以及包含 site.py 的附加子目录(例如 \Lib\)。