简体   繁体   English

如何在新的 Windows 终端打开 Python 文件?

[英]How to open Python files in the new Windows Terminal?

I'm trying out the Windows Terminal app and I want to start using it instead of CMD. The problem is, I cannot set the File Explorer to open Python files with it by default.我正在试用 Windows 终端应用程序,我想开始使用它而不是 CMD。问题是,我无法将文件资源管理器设置为默认使用它打开 Python 文件。 I tried using the Open button leading to the file path, but I get the following error我尝试使用通向文件路径的“打开”按钮,但出现以下错误

wt重量
The file cannot be accessed by the system.系统无法访问该文件。

With Windows 10, there is no way to change the default terminal from Windows Console Host to Windows Terminal.对于 Windows 10,无法将默认终端从 Windows 控制台主机更改为 Windows 终端。

However, with Windows 11, it is now possible to change the default terminal application.但是,在 Windows 11 中,现在可以更改默认终端应用程序。 This currently needs a Windows Terminal Preview version.这当前需要 Windows Terminal Preview 版本。

You can activate this from either in Windows 11 Settings ( Choose the default terminal app to host the user interface for command-line applications ) or in Windows Terminal Preview ( Settings->Startup->Default Terminal Application )您可以在 Windows 11 设置(选择默认终端应用程序来托管命令行应用程序的用户界面)或 Windows 终端预览(设置->启动->默认终端应用程序)中激活它

You can have this behaviour on double click by changing您可以通过更改双击来获得此行为

HKEY_CLASSES_ROOT\Python.File\Shell\open\command HKEY_CLASSES_ROOT\Python.File\Shell\open\command

default value from:默认值来自:

"C:\Windows\py.exe" "%L" % * "C:\Windows\py.exe" "%L" % *

to

"C:\Users\USER\AppData\Local\Microsoft\WindowsApps\wt.exe" "python" "%L" % * "C:\Users\USER\AppData\Local\Microsoft\WindowsApps\wt.exe" "python" "%L" % *

(you have to replace "USER" with the username on your windows machine) (你必须用你的 windows 机器上的用户名替换“USER”)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用python打开新终端并在新终端中运行命令 - How to open new terminal and run command in the new terminal using python 如何使用 Python 打开新的 bash 终端 - How to open new bash terminal using Python 如何打开Python终端? - How to open Python Terminal? 如何使python以普通用户而不是以root用户身份打开新终端 - How to make python open new Terminal as normal user and not as root user 在新的终端窗口上打开并执行python脚本 - Opening and executing python scripts on new terminal windows 如何在 Windows 10 上打开和查看 Python PY 文件? - How do I open and view Python PY files on Windows 10? 如何在新终端中打开子进程(在 python 脚本中)并在 15 秒后将其终止(平台:Ubuntu) - How to open a subprocess (within a python script) in new terminal and kill it after 15 seconds (Platform: Ubuntu) 如何在 Windows/Anaconda 终端上运行 .py 文件? - How to run .py files on Windows/Anaconda terminal? 在已经打开和配置的 python 终端中运行 VScode Jupyter Notebook 单元(而不是打开一个新终端) - Running VScode Jupyter Notebook cells in already open and configured python terminal (rather than open a new terminal) 如何使用一个python脚本打开Powershell终端? - How to open a powershell terminal with one python script?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM