この記事について
https://qiita.com/fiftystorm36/items/b2fd47cf32c7694adc2e
↑の記事に従って環境構築していたところ
$ .\venv\Scripts\activate
というコマンドで以下のエラーが出て躓いた。
.\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」を右クリックし、「管理者として実行」を選択。
現在の実行ポリシーを確認(オプション)
$ Get-ExecutionPolicy
通常は「Restricted」と表示されます。
2. 実行ポリシーを変更
全ユーザーに適用する場合(管理者権限が必要):
$ Set-ExecutionPolicy RemoteSigned
現在のユーザーにのみ適用する場合(管理者権限は不要):
$ Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser
コマンドを入力すると、変更の確認を求められます。
「Y」または「A」を入力して、変更を承認します。
仮想環境を再度アクティブ化
.\venv\Scripts\activate
注意事項:
セキュリティリスク: 実行ポリシーを変更すると、悪意のあるスクリプトが実行されるリスクが高まります。信頼できるスクリプトのみを実行するようにしてください。
元に戻す方法:
必要に応じて、実行ポリシーを元の「Restricted」に戻すことができます。
$ Set-ExecutionPolicy Restricted
これで仮想環境に入ることが出来ました。