VSCODE与Python,在VENV之前执行命令
由于公司约束,我无法立即执行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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
VS代码支持添加
tasks.json
文件以设置自动任务。一个简单的示例:
此设置是运行
dir
命令在打开文件夹时读取目录中的文件。如何创建
task.json
file?用 ctrl> ctrl + shift> shift 打开命令调色板 + p
搜索并选择任务:配置任务
更多有关
tasks.json
: 单击此处ps:
涉及调试,
启动。 JSON
文件也可以很有帮助。单击在这里文档/编辑/调试#_launch-configurations“ rel =“ nofollow noreferrer”>在这里了解更多。VS Code supports adding
tasks.json
files to set up automatic tasks.A simple example:
This setting is to run the
dir
command to read the files in the directory when opening the folder.How to create a
task.json
file?Open command palette with Ctrl+Shift+P
Search and select Tasks:Configure Task
Choose Create task.json file fromtemplate
Choose Others
More about
tasks.json
: Click herePS:
Regarding debugging, the
launch.json
file can also help a lot. Click here and here to know more.