完整报错内容:

File C:\Users\Lenovo\Documents\WindowsPowerShell\profile.ps1 cannot be loaded because running scripts is disabled o n this system. For more information, see about_Execution_Policies at https:/go.microsoft.com/fwlink/?LinkID=135170. At line:1 char:3 + . 'C:\Users\Lenovo\Documents\WindowsPowerShell\profile.ps1' + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : SecurityError: (:) [], PSSecurityException + FullyQualifiedErrorId : UnauthorizedAccess

报错背景:

在vs提供的Developer Command Prompt中,为Visio Studio配置AirSim时,运行build.cmd报错

报错原因:

1. PowerShell 脚本运行被禁用

File C:\Users\Lenovo\Documents\WindowsPowerShell\profile.ps1 cannot be loaded because running scripts is disabled on this system.

这是由于 PowerShell 的默认执行策略设置为 Restricted,该策略禁止运行任何脚本。

解决方案:

0.打开 PowerShell:

  • 你需要在 PowerShell 中运行 Set-ExecutionPolicy 命令,而不是在命令提示符(CMD)或者vs提供的prompt中。

  • 打开 PowerShell 的方法:

    • 在开始菜单中搜索“PowerShell”。

    • 右键点击“Windows PowerShell”,选择“以管理员身份运行”

  1. 更改执行策略:

    • 在以管理员身份打开的 PowerShell 中,运行以下命令来查看当前的执行策略

      Get-ExecutionPolicy
    • 如果当前策略是 Restricted,你可以将其更改为 RemoteSigned,这样可以运行本地脚本,但远程脚本需要签名

      Set-ExecutionPolicy RemoteSigned -Scope CurrentUser

      或者,如果你想允许所有脚本运行(不推荐,因为存在安全风险)

      Set-ExecutionPolicy Unrestricted -Scope CurrentUser

      如果系统提示确认,输入 Y 并按回车键。

  2. 验证更改是否生效:

    • 再次运行以下命令来确认执行策略已更改

      Get-ExecutionPolicy

      如果显示 RemoteSigned 或 Unrestricted,则说明更改成功

4.再次在vs提供的prompt中运行build.cmd就不会报错了。

Logo

北京人形旗下天工造物具身智能开源社区,聚焦具身天工与慧思开物两大平台

更多推荐