Ric*_*cha 3 powershell command-line visual-studio-code vscode-settings
在Visual Studio代码内部,我试图从命令行执行script.bat,但出现以下错误:
无法加载文件C:\ Theses_Repo \ train-cnn \ environment \ Scripts \ activate.ps1,因为此系统上的运行脚本已禁用。
读完这篇文章后,我试图以管理员模式运行Visual Studio代码,以为问题出在特权上。但是无论如何都会抛出错误。
Abd*_*bdu 97
为了更简单,除了 Ricardo 的答案之外,我还想添加 vs 代码设置路径。你可以这样得到它:
文件 -> 首选项 -> 设置并在搜索栏中写入“自动化”。
之后,通过查看您的操作系统输入“edit in settings.json”。
最后,在大括号中添加以下 b/n:
"terminal.integrated.shellArgs.windows": ["-ExecutionPolicy", "Bypass"]
Run Code Online (Sandbox Code Playgroud)
nul*_*ull 68
从 Visual Studio Code 处理此问题的最简单方法是从 powerShell 更改为 cmd(假设在您的情况下没有理由使用 powershell)。为此,请按照以下几个步骤操作:
我在目前的答案中还没有找到这样的解决方案。希望有帮助!
jay*_*sia 38
面对同样的问题,这对我有用。以管理员身份打开 PowerShell 并粘贴它。
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
Run Code Online (Sandbox Code Playgroud)
Moi*_*hyS 30
问题是 PowerShell 默认限制运行脚本,除非我们更改执行策略。
我们可以通过添加-ExecutionPolicy Bypassargs来更改执行策略。在 vscode 中,您必须通过在 settings.json(ctrl + shift + p 并键入“settings.json”)中添加以下参数来创建带有这些参数的 shell 配置文件
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell",
"args": ["-ExecutionPolicy", "Bypass"]
}
},
"terminal.integrated.defaultProfile.windows": "PowerShell",
Run Code Online (Sandbox Code Playgroud)
注意:terminal.integrated.shellArgs设置已被弃用。
Bar*_*i r 17
打开VS代码
文件 -> 首选项 -> 设置
在搜索栏中 -> 搜索“terminal.integrated.shellArgs”
单击 Terminal>integrated>ShellArgs>windows 的“Edit in setting.json”[无论您使用什么操作系统,请选择相应的设置]
在 json 文件的顶部添加以下内容:
terminal.integrated.shellArgs.windows": ["-ExecutionPolicy", "Bypass"]
例如在添加你的 json 之后可能看起来像:
Run Code Online (Sandbox Code Playgroud){ "terminal.integrated.shellArgs.windows": ["-ExecutionPolicy", "Bypass"], "git.autofetch": true, "peacock.favoriteColors": [ { "name": "Angular Red", "value": "#b52e31" }, { "name": "Auth0 Orange", "value": "#eb5424" },
小智 13
由于 Windows 10 上的安全原因,我遇到了同样的问题。我设法通过在 PowerShell 中运行以下命令来修复它:
Set-ExecutionPolicy -ExecutionPolicy Unrestricted
Run Code Online (Sandbox Code Playgroud)
pix*_*ata 12
按键盘上的 windows 按钮
输入“PowerShell”
右键单击 Windows PowerShell
单击以管理员身份运行
运行以下命令并用“Y”确认
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope LocalMachine
更多信息:https : //www.roelpeters.be/solved-running-scripts-is-disabled-on-this-system-in-powershell/
我在这里发现,您可以将以下内容添加到Visual Studio代码设置中,问题将消失:
"terminal.integrated.shellArgs.windows": ["-ExecutionPolicy", "Bypass"]
Run Code Online (Sandbox Code Playgroud)
原因是,在构建命令行集成(如Visual Studio代码)时,您需要自行设置命令行策略。通过设置以上配置,Visual Studio代码将为您完成此任务。
(阅读此内容可以更好地了解命令行策略)
小智 8
我以管理员身份打开 VS Code 并在终端中运行此命令:
Set-ExecutionPolicy Unrestricted
Run Code Online (Sandbox Code Playgroud)
它允许我运行脚本而不会出错。
小智 7
在 JSON 文件的顶部添加以下内容:
"terminal.integrated.defaultProfile.windows": "PowerShell",
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"args": [
"-ExecutionPolicy",
"Bypass"
]
}
},
Run Code Online (Sandbox Code Playgroud)
注意:不推荐使用以下设置行:
"terminal.integrated.shellArgs.windows": ["-ExecutionPolicy", "Bypass"]
Run Code Online (Sandbox Code Playgroud)
小智 5
解决问题的步骤,
获取执行策略-列表
Set-ExecutionPolicy -范围当前用户不受限制
| 归档时间: |
|
| 查看次数: |
3666 次 |
| 最近记录: |