VSCODE与Python,在VENV之前执行命令

发布于 2025-02-11 19:23:28 字数 561 浏览 1 评论 0原文

由于公司约束,我无法立即执行PowerShell命令:

File C:...Activate.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see 
about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170

我已经找到的解决方法(感谢Stack!)是在命令行中执行(不是作为PS脚本):

Set-ExecutionPolicy Unrestricted -Scope Process

这解决了问题,当我运行代码时, ,效果很好。但是,当我在VS代码中的开发/调试会话中间时,此命令不执行。

JSON设置文件之一中是否有一个位置,我可以在PS或CMD之前预先执行上述命令,或者可以在Python调试器尝试运行activate.ps1?这解决了我和其他任何具有有问题的公司脚本执行政策的人的VENV问题。

Due to company constraints I cannot immediately execute PowerShell commands:

File C:...Activate.ps1 cannot be loaded because running scripts is disabled on this system. For more information, see 
about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170

The workaround I already found (thanks Stack!) is to execute, in the command line (not as a PS script):

Set-ExecutionPolicy Unrestricted -Scope Process

This solves the problem and when I'm running code for real, it works well. When I am in the middle of a development/debugging session in VS Code, however, this command does not execute.

Is there a place in one of the JSON setup files where I can pre-execute the above command before PS or cmd or the python debugger attempts to run Activate.ps1? This fixes venv problems for me and anyone else with problematic corporate script execution policies.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

二智少女猫性小仙女 2025-02-18 19:23:29

VS代码支持添加tasks.json文件以设置自动任务。

一个简单的示例:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "test",
            "type": "shell",
            "command": "dir",
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": false
            },
            "runOptions": {
                "runOn": "folderOpen"
            }
        }
    ]
}

此设置是运行dir命令在打开文件夹时读取目录中的文件。

如何创建task.json file?

  1. ctrl> ctrl + shift> shift 打开命令调色板 + p

  2. 搜索并选择任务:配置任务

    “配置任务”

  3. “

  4. “在此处输入图像描述”

更多有关tasks.json 单击此处

ps:

涉及调试,启动。 JSON文件也可以很有帮助。单击在这里文档/编辑/调试#_launch-configurations“ rel =“ nofollow noreferrer”>在这里了解更多。

VS Code supports adding tasks.json files to set up automatic tasks.

A simple example:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "test",
            "type": "shell",
            "command": "dir",
            "presentation": {
                "echo": true,
                "reveal": "always",
                "focus": false,
                "panel": "shared",
                "showReuseMessage": true,
                "clear": false
            },
            "runOptions": {
                "runOn": "folderOpen"
            }
        }
    ]
}

This setting is to run the dir command to read the files in the directory when opening the folder.

enter image description here

How to create a task.json file?

  1. Open command palette with Ctrl+Shift+P

  2. Search and select Tasks:Configure Task

    configure task

  3. Choose Create task.json file fromtemplate

    creshhssshsshfhate

  4. Choose Others

    enter image description here

More about tasks.json: Click here

PS:

Regarding debugging, the launch.json file can also help a lot. Click here and here to know more.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文