【问题标题】:How can I check all the installed Python versions on Windows?如何在 Windows 上检查所有已安装的 Python 版本?
【发布时间】:2018-11-15 04:49:17
【问题描述】:

请注意,我不是询问“如何检查我安装了哪个版本的 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提供的工具或者操作系统能做到.

【问题讨论】:

  • 如果您使用 conda 安装版本,请在您的 cmd 中键入 conda env list。 Link to conda doc
  • 如果您查看已安装程序的列表会怎样?每个 python 版本可能有一个条目。
  • @Patol75 我正在使用 Microsoft Window 10。在我的“开始”菜单中,对于 Python 3.7,似乎没问题,我可以看到 IDLE、Python 3.7、Python 3.7 Module Docs for 32 和 64少量。但是对于 Python 2.7,菜单中只有 Python 2.7 32-bit。但我可以通过运行 py -2.7-64 来启动 Python 2.7 64 位。这意味着“py.exe”能够找到我的 64 位 Python 2.7 版本。
  • 我在想这样的事情 (kencenerelli.wordpress.com/2017/11/25/…),甚至只是 Windows 设置中的应用和功能。

标签: python windows


【解决方案1】:

我刚刚得到了答案。通过输入“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

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

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

而“-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

【讨论】:

  • 我猜这需要 Python 3.7。使用 Python 3.6 py -0 返回 Requested Python version (0) not installed
  • 我也无法使用该命令,因为它返回Requested Python version (0) not installed
  • 它向我显示了错误command not found: py,尝试使用完全没有-0 参数的python -h
【解决方案2】:

如果py -0p 不适合你:

解决方案

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

引用

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

说明

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

由于 dir <filename> /s 返回 within 指定目录和所有子目录的出现,请从 C 驱动器运行此命令(除非您只想在特定目录下检查,例如检查用户的 Python 安装)。

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

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

【讨论】:

  • "PS C:\> dir site.py -s -ErrorAction SilentlyContinue" 在我的 Windows 10 上什么也没打印。但是这台电脑有 python。 "Python 3.9.7 (tags/v3.9.7:1016ef3, Aug 30 2021, 20:19:38) [MSC v.1929 64 bit (AMD64)] on win32"
【解决方案3】:

正如我从运行 python -2 得到的,

Requested Python version (2) not installed, use -0 for available pythons PS C:\Users\ASUS> py -0 Installed Pythons found by C:\Windows\py.exe Launcher for Windows -3.9-64 *

如中,使用命令py -0

【讨论】:

  • 这个问题已经有类似的解答和详细的解释了,不需要再回答了。
猜你喜欢
  • 2015-08-08
  • 2018-06-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-16
  • 2016-09-18
  • 2021-04-26
相关资源
最近更新 更多