- Disable the existing app execution alias for python. By default, if you type
pythonin the terminal and it’s not installed, it’ll prompt you to install it from the Microsoft Store. This isn’t the behavior we want, so we need to disable it. Hit the Windows Search icon and search for ‘Manage App Execution Aliases’ - after launching it, click on the two sliders for ‘App Installer’ marked ‘python.exe’ and python3.exe’ to the left to disable these.
Next, we’re going to install pyenv-win. This allows us to manage python versions on the command line and set defaults globally, or even locally in specific projects. The [github repo]() for pyenv-win has several options to install; the one I prefer is to just execute
git clone https://github.com/pyenv-win/pyenv-win.git "$HOME/.pyenv"from a PowerShell prompt.
Now, to add the appropriate environment variables, run the following in the PowerShell prompt - this is all documented at the repo above.
[System.Environment]::SetEnvironmentVariable('PYENV',$env:USERPROFILE + "\.pyenv\pyenv-win\","User") [System.Environment]::SetEnvironmentVariable('PYENV_HOME',$env:USERPROFILE + "\.pyenv\pyenv-win\","User") [System.Environment]::SetEnvironmentVariable('path', $HOME + "\.pyenv\pyenv-win\bin;" + $HOME + "\.pyenv\pyenv-win\shims;" + $env:Path,"User")
Restart your PowerShell Window and run
pyenv- this should list the version and flags for pyenv. To see the list of available versions, run
pyenv install -l. If you don’t have a specific version you need, I recommend picking the most current version of python 3 for your version of Windows. For 32-bit Windows, the appropriate versions have “-win32” at the end. Install that version with
pyenv install $versionwhere $version is the one you’re installing (ex:
pyenv install 3.8.2).
Select the version you just installed as the global version by running
pyenv global $versionwhere $version is the one you just installed (ex:
pyenv global 3.8.2).
pyenv rehashto update pyenv with the newly installed version.
That’s it! Following that, you’ll have the ability to use pyenv to manage multiple python versions on Windows. This is especially useful when you’re using other languages (such as Node) where modules may take a dependency on a specific python version.