pyenv
can be used in Linux/MacOS for python version management. pyenv-win
is the fork of pyenv
which can be used on Windows.
Tested on Mac Catalina
Install pyenv
.
brew install pyenv
Add following to your shell config file:
.bashrc
/.bash_profile
- For Bash.zshrc
- For Zshexport PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
Restart your shell. Start a new shell or run exec "$SHELL"
in your current shell.
Tested on Arch Linux
Install pyenv
on your system.
curl https://pyenv.run | bash
Follow same steps as in Step 2 and 3 of MacOS installation.
Install pyenv-win
on Windows.
In Powershell
pip install pyenv-win --target "$HOME\.pyenv"
In cmd.exe
pip install pyenv-win --target "%USERPROFILE%\.pyenv"
Setup the environment variables using Powershell/Terminal.
[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")
Close and re-open your terminal. Run pyenv --version
on the terminal.
a. If the return value is the installed version of pyenv, then continue below. b. If you receive a command not found error, ensure the environment variables are properly set via the GUI: This PC ? Properties ? Advanced system settings ? Advanced ? Environment Variables... ? PATH c. If you receive a command not found error and you are using Visual Studio Code or another IDE with a built in terminal, restart it and try again.
Run pyenv rehash
from the home directory.
pyenv versions
Example
$ pyenv versions
* system (set by /home/souser/.pyenv/version)
3.6.9
pyenv install <version-number>
pyenv uninstall <version-number>
pyenv global <version-number> # <version-number> is the name assigned to your python in output of `pyenv versions`
Example
$ python --version
Python 3.9.1
$ pyenv global 3.6.9
$ python --version
Python 3.6.9
Set a python version for a directory and all it's sub-directories
pyenv local <version-number> # <version-number> is the name assigned to your python in output of `pyenv versions`
Example
~/tmp/temp$ python --version
Python 3.9.1
~/tmp/temp$ pyenv local 3.6.9
~/tmp/temp$ python --version
Python 3.6.9
For more details, you can check the Github repos : pyenv and pyenv-win.