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でスクリプトが実行できないときの対処方法

Posted at

WindowsのTerminalでPowerShellを使っていて、ダウンロードしてきたスクリプトを実行しようとしたところ以下のようなエラーになり、実行できませんでした。

PS C:\Users\toshi\uroarm> .\venv\Scripts\activate
.\venv\Scripts\activate : このシステムではスクリプトの実行が無効になっているため、ファイル C:\Users\toshi\uroarm\venv\S
cripts\Activate.ps1 を読み込むことができません。詳細については、「about_Execution_Policies」(https://go.microsoft.com/f
wlink/?LinkID=135170) を参照してください。
発生場所 行:1 文字:1
+ .\venv\Scripts\activate
+ ~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : セキュリティ エラー: (: ) []、PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess
PS C:\Users\toshi\uroarm>

いろいろと検索した結果、以下のような流れで解消できました。

Terminalを管理者モードで起動します。

起動の仕方は、スタートメニューを右クリックして「ターミナル(管理者)」をクリックして起動します。

image.png

タブに、「管理者:Windows PowerShell」と表示されたターミナルが起動します。

image.png

これで管理者権限のあるPowerShellが起動しましたので、PowerShellの実行ポリシーを確認します。

Get-ExecutionPolicy

Restricted と表示されたらスクリプトの実行が制限されています。

ポリシーを緩めるので、このPowerShellが実行されている間だけにしておきます。

Set-ExecutionPolicy RemoteSigned -Scope Process

以上で、スクリプトが実行できるようになりました!

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?