0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Windows11でPythonのvenvを使い仮想環境を構築する際に、"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."というエラーに当たった際の解決方法。

Last updated at Posted at 2024-10-13

この記事について

https://qiita.com/fiftystorm36/items/b2fd47cf32c7694adc2e
↑の記事に従って環境構築していたところ

sh
$ .\venv\Scripts\activate 

というコマンドで以下のエラーが出て躓いた。

sh
.\venv\Scripts\activate : File C:\Users\sophytoeat\NeuralClothSim\venv\Scripts\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.
At line:1 char:1
+ .\venv\Scripts\activate
+ ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : SecurityError: (:) [], PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

環境

Unreal Engine 5.4.4
Python 3.13.0
PowerShell

解決方法

エラーメッセージは、PowerShellの実行ポリシーが原因でスクリプトが実行できないことを示しているらしい。デフォルトでは、PowerShellはセキュリティ上の理由からスクリプトの実行を制限しているようだ。

解決方法: 実行ポリシーを変更する

以下の手順で実行ポリシーを変更し、スクリプトの実行を許可する。

1. PowerShellを管理者として起動

スタートメニューで「Windows PowerShell」を検索。
「Windows PowerShell」を右クリックし、「管理者として実行」を選択。
現在の実行ポリシーを確認(オプション)

sh
$ Get-ExecutionPolicy

通常は「Restricted」と表示されます。

2. 実行ポリシーを変更

全ユーザーに適用する場合(管理者権限が必要):

sh
$ Set-ExecutionPolicy RemoteSigned

現在のユーザーにのみ適用する場合(管理者権限は不要):

sh
$ Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

コマンドを入力すると、変更の確認を求められます。

「Y」または「A」を入力して、変更を承認します。
仮想環境を再度アクティブ化

sh
.\venv\Scripts\activate

注意事項:

セキュリティリスク: 実行ポリシーを変更すると、悪意のあるスクリプトが実行されるリスクが高まります。信頼できるスクリプトのみを実行するようにしてください。

元に戻す方法:

必要に応じて、実行ポリシーを元の「Restricted」に戻すことができます。

sh
$ Set-ExecutionPolicy Restricted

これで仮想環境に入ることが出来ました。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?