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?

【Python】Windows11 に pyenv-win をインストールする

Last updated at Posted at 2025-07-14

1. はじめに

Windows11でPythonのバージョン管理を行うために、pyenv-win (Windows版の pyenv)をインストールする方法を記載する。

2. 使用環境

  • OS: Windows 11 Pro 24H2

3. インストール手順

3-1. Windows PowerShell を管理者権限で開く

Windows PowerShell を検索し、右クリックして「管理者として実行」を選択する。

3-2. 現在の実行ポリシーを確認する

PS C:\WINDOWS\system32> Get-ExecutionPolicy
Restricted

参考: PowerShell 実行ポリシー

3-3. 実行ポリシーを緩和する

先ほど確認した実行ポリシーによっては、pyenv-win インストール時にエラーが発生する場合がある。
そのため、実行ポリシーを一時的に緩和する。

PS C:\WINDOWS\system32> Set-ExecutionPolicy RemoteSigned

実行ポリシーの変更
実行ポリシーは、信頼されていないスクリプトからの保護に役立ちます。実行ポリシーを変更すると、about_Execution_Policies
のヘルプ トピック (https://go.microsoft.com/fwlink/?LinkID=135170)
で説明されているセキュリティ上の危険にさらされる可能性があります。実行ポリシーを変更しますか?
[Y] はい(Y)  [A] すべて続行(A)  [N] いいえ(N)  [L] すべて無視(L)  [S] 中断(S)  [?] ヘルプ (既定値は "N"): Y

3-4. pyenv-win インストール

カレントディレクトリをホームフォルダなどにして、pyenv-win をインストールする。
(インストール先は任意だが、ホームフォルダ推奨。)

参考: pyenv-win - GitHub

PS C:\WINDOWS\system32> cd ~
PS C:\Users\user> Invoke-WebRequest -UseBasicParsing -Uri "https://raw.githubusercontent.com/pyenv-win/pyenv-win/master/pyenv-win/install-pyenv-win.ps1" -OutFile "./install-pyenv-win.ps1"; &"./install-pyenv-win.ps1"
pyenv-win 3.1.1 installed.
No updates available.
PS C:\Users\user> Invoke-WebRequest -UseBasicParsing -Uri "https://raw.githubusercontent.com/pyenv-win/pyenv-win/master/pyenv-win/install-pyenv-win.ps1" -OutFile "./install-pyenv-win.ps1"; &"./install-pyenv-win.ps1"


    ディレクトリ: C:\Users\user


Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
d-----   2025/07/14 ()     22:04                .pyenv
pyenv-win is successfully installed. You may need to close and reopen your terminal before using it.

ちなみに、3-3. で実行ポリシーを変更しなかった場合、次のようなエラーが発生した。

PS C:\Users\user> Invoke-WebRequest -UseBasicParsing -Uri "https://raw.githubusercontent.com/pyenv-win/pyenv-win/master/pyenv-win/install-pyenv-win.ps1" -OutFile "./install-pyenv-win.ps1"; &"./install-pyenv-win.ps1"
& : このシステムではスクリプトの実行が無効になっているため、ファイル C:\Users\user\install-pyenv-win.ps1 を読み込むこ
とができません。詳細については、「about_Execution_Policies(https://go.microsoft.com/fwlink/?LinkID=135170) を参照して
ください。
発生場所 :1 文字:173
+ ... n.ps1" -OutFile "./install-pyenv-win.ps1"; &"./install-pyenv-win.ps1"
+                                                 ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : セキュリティ エラー: (: ) []、PSSecurityException
    + FullyQualifiedErrorId : UnauthorizedAccess

3-5. 実行ポリシーを元に戻す

セキュリティリスクの観点から、3-2 で確認したポリシー(Restricted)に戻す。

PS C:\Users\user> Set-ExecutionPolicy Default

実行ポリシーの変更
実行ポリシーは、信頼されていないスクリプトからの保護に役立ちます。実行ポリシーを変更すると、about_Execution_Policies
のヘルプ トピック (https://go.microsoft.com/fwlink/?LinkID=135170)
で説明されているセキュリティ上の危険にさらされる可能性があります。実行ポリシーを変更しますか?
[Y] はい(Y)  [A] すべて続行(A)  [N] いいえ(N)  [L] すべて無視(L)  [S] 中断(S)  [?] ヘルプ (既定値は "N"): Y
PS C:\Users\user> Get-ExecutionPolicy
Restricted

以降コマンドプロンプトで pyenv を使う場合は戻した方がいいかもしれないが、PowerShellやVSCodeで実行ポリシーのエラーが出る場合は変更したままにする。

3-6. pyenvのバージョン確認

インストールされたか、パスが設定されているかどうかを確認する。
以降、管理者権限は不要であるため、PowerShellを開き直す。(一度開き直さないと、コマンド実行時にエラーになることもあった。)

C:\Users\user>pyenv --version
pyenv 3.1.1

エラーが出る場合は、環境変数設定でパスを確認し、無ければ追加する。

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?