繁体   English   中英

没有 PowerShell 的 Visual Studio 代码中的 Python

[英]Python in Visual Studio Code without PowerShell

所以我的工作需要使用 Python。 不幸的是,由于最近的黑客攻击,公司的安全政策非常严格,我无法获得管理员权限。 我设法说服我们的 IT 在我的计算机上安装 Python、Visual Studio Code 和 Python 扩展。

如果我尝试在 Python 解释器中运行 python 命令,它就可以工作。 但是,当我尝试在 Visual Studio Code 中运行 Python 脚本时,它必须运行 Power Shell,出于安全原因,它也被阻止。 我收到以下错误:

终端进程命令“C:\WINDOWS\System32\WindowsPowerShell\v1.0\powershell.exe”启动失败(退出代码:{2})

有没有办法解决这个问题? 尽管有所有安全限制,但要在 Visual Studio Code 中使用 Python?

我尝试询问我们的 IT 部门,但他们不知道如何帮助我...

先感谢您。

您可以更改 VS Code 设置并告诉它不要在集成终端中使用 PowerShell 作为 shell。

For example, I have put Windows Terminal in there, but you can also use CMD or any other shell such a git bash as long as it's available in your system.

ctrl+shift+p并输入/选择Open Settings (JSON) 然后将以下一些内容添加到此配置文件中,并保存。

对于 Windows 端子:

"terminal.external.windowsExec": "C:\\Users\\<your-username>\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe"

对于 CMD:

"terminal.external.windowsExec": "C:\\Windows\\system32\\cmd.exe"

这很简单。 你可以做到这一点,别担心。

您可以从 Visual Studio Code 中获得如何执行 python 代码的答案。 这是链接** https://stackoverflow.com/questions/29987840/how-to-execute-python-code-from-within-visual-studio-**code#:~:text=How%20to%20execute %20Python%20code%20from%20within%20Visual%20Studio%20Code

这是一种简单的方法,您不需要任何配置:

1.安装代码运行器扩展( https://marketplace.visualstudio.com/items?itemName=formulahendry.code-runner或者你可以简单地按照这个路径:打开VS代码编辑器→go到扩展(打开扩展按Ctrl + shift + x同时) → 搜索 CODE RUNNER → 安装它。

2.在文本编辑器中打开 Python 代码文件,然后使用快捷键Ctrl + Alt + N ,或按 F1 然后选择/键入运行代码。 代码将运行,output 将显示在 Output Window 中。

嘿朋友,如果你想添加 Python 路径,你可以 go 到菜单文件 → 首选项 → 设置,然后添加 Python 路径如下:

"code-runner.executorMap": 

**{ "python": "\"C:\\Program Files\\Python35\\python.exe\"" }**

试试看...

或者

尝试这个,

我认为您应该必须安装 python https://www.python.org/downloads/。

安装 python 的 .exe 文件后。 Go 下载到您已下载 .exe 文件的位置,双击打开它。

在此处输入图像描述

它看起来像上面的 window。 在点击现在安装之前点击**将 python 3.9.6 添加到 PATH。** 然后安装它。

现在,将 go 转换为 VS 代码并尝试您的程序。

暂无
暂无

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM