Skip to main content
 首页 » 编程设计

python之如何将 Python 3.3 添加到 Powershell

2025年05月04日14sky-heaven

嘿,我一直在尝试通过将路径中的 27 替换为 33 来将 Python 3.3 添加到 windows powershell。

我尝试发布屏幕截图,但结果我需要 10 个代表,所以我只复制并粘贴我尝试过的内容:

[Enviroment]::SetEnviromentVariable("Path", "$env:Path;C:\Python33", "User") 

>

[Enviroment]::SetEnviromentVariable("Path", "$env:Path;C:\Python33") 

>

[Enviroment]::SetEnviromentVariable("Path", "$env:Path;C:\Python33\python.exe", "User") 

>

[Enviroment]::SetEnviromentVariable("Path", "$env:Path;C:\Python33;C:\Python33\Scripts", "User") 

>

[Enviroment]::SetEnviromentVariable("Path", "$env:Path;C:\Python33\", "User") 

python.exe所在文件夹路径为:C:\Python33

我在某个地方做错了,但不确定在哪里。 帮助一个人尝试编程?

谢谢。

请您参考如下方法:

Python 3.3 附带 PyLauncher (py.exe),它安装在 C:\Windows 目录(已在路径中),并使任何已安装的 Python 都可以通过命令行执行,如下所示:

Windows PowerShell 
Copyright (C) 2009 Microsoft Corporation. All rights reserved. 
 
PS C:\> py 
Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:19:30) [MSC v.1600 64 bit (AMD64)] on win32 
Type "help", "copyright", "credits" or "license" for more information. 
>>> ^Z 
 
PS C:\> py -2 
Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32 
Type "help", "copyright", "credits" or "license" for more information. 
>>> ^Z 
 
PS C:\> py -3 
Python 3.3.3 (v3.3.3:c3896275c0f6, Nov 18 2013, 21:19:30) [MSC v.1600 64 bit (AMD64)] on win32 
Type "help", "copyright", "credits" or "license" for more information. 
>>> 

请注意,如果同时安装了 2.X 和 3.X,则默认的 Python 为 2.X(在更高版本的 Python 中为 3.X),但这可以用 -3 覆盖通过设置 PY_PYTHON 环境变量来切换或更改默认值。

此外,如果您最后安装 Python 3.3 并注册扩展,PyLauncher 将成为 .py 文件的默认程序,并在脚本顶部添加特殊的 #! 注释将指定版本用于脚本的 Python。这允许您在桌面上拥有 Python 2 和 Python 3 文件,只需双击它们即可为该脚本运行正确版本的 Python。

参见 Python Launcher for Windows在Python 3 docs .