Multiple python versions on one computer : pyenv
Python version switcher
Multiple python versions on one computer : pyenv
It’s been years I have been stoped installing nodejs directly into the machine. I always use nvs to install mutiple node versions in the machine and switch between versions as necessary when working in different projects.
I decided to figure out how can I have multiple version of python installed on my machine similar to the experience with node version switcher nvs. pyenv lets you easily switch between multiple versions of Python.
pyenv GitHub:https://github.com/pyenv/pyenv
What pyenv does:
- Lets you change the global Python version on a per-user basis.
- Provides support for per-project Python versions.
- Allows you to override the Python version with an environment variable.
Check which python used in the machine:
which python
Check the python version currently in use:
python --version
Installation
MacOS
brew update
brew install pyenv
Set up shell environment for pyenv
After installation update the shell configuration file .zshrc
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init - zsh)"' >> ~/.zshrc
If you wish to get Pyenv in noninteractive login shells as well, also add the commands to ~/.zprofile or ~/.zlogin.
Restart your shell
for the PATH changes to take effect.
exec "$SHELL"
Using pyenv
There are lots of commands in *pyenv*, You can see them using:
pyenv commands
List Of Python Versions
To see all the python versions
pyenv install --list
To see all the available versions
pyenv install --list | grep " 3\."
Install a Python version
o install additional Python versions, use [pyenv install](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-install).
For example, to download and install Python 3.10.4, run:
pyenv install 3.10.4
Prefix auto-resolution to the latest version
All Pyenv subcommands except uninstall automatically resolve full prefixes to the latest version in the corresponding version line.
pyenv install picks the latest known version, while other subcommands pick the latest installed version.
E.g. to install and then switch to the latest 3.10 release:
pyenv install 3.10
pyenv global 3.10
Check python versions installed using pyenv:
pyenv versions
Switch between Python versions
To select a Pyenv-installed Python as the version to use, run one of the following commands:
[pyenv shell <version>](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-shell) -- select just for current shell session[pyenv local <version>](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-local) -- automatically select whenever you are in the current directory (or its subdirectories)[pyenv global <version>](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-shell) -- select globally for your user account
E.g. to select the above-mentioned newly-installed Python 3.10.4 as your preferred version to use:
pyenv global 3.10.4
Now whenever you invoke python, pip etc., an executable from the Pyenv-provided 3.10.4 installation will be run instead of the system Python.
Using “system" as a version name would reset the selection to your system-provided Python.
Uninstall Python versions
As time goes on, you will accumulate Python versions in your $(pyenv root)/versions directory.
To remove old Python versions, use [pyenv uninstall <versions>](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md#pyenv-uninstall).
Alternatively, you can simply rm -rf the directory of the version you want to remove. You can find the directory of a particular Python version with the pyenv prefix command, e.g. pyenv prefix 2.6.8. Note however that plugins may run additional operations on uninstall which you would need to do by hand as well. E.g. Pyenv-Virtualenv also removes any virtual environments linked to the version being uninstalled.
Useful links:
4. Using Python on Windows — Python 3.15.0a5 documentation
5. Using Python on macOS — Python 3.15.0a5 documentation
12. Virtual Environments and Packages — Python 3.15.0a5 documentation
메타데이터
- post_id
- 4a7ab84ffe3e
- slug
- multiple-python-versions-on-one-computer-pyenv-4a7ab84ffe3e
- url
- https://medium.com/@gayashan4lk/multiple-python-versions-on-one-computer-pyenv-4a7ab84ffe3e
- canonical_url
- https://medium.com/@gayashan4lk/multiple-python-versions-on-one-computer-pyenv-4a7ab84ffe3e
- author_url
- https://medium.com/@gayashan4lk
- status
- ok
- fetched_at
- 2026-06-29 01:02:39