As far as I know, pyenv-virtualenv is the best Python version management tool.
Have you ever experienced any of these before?
- Conflict between pip and co*da in an environment.
- Forgot to change the environment with "co*da activate".
- When using pyenv, you want to create multiple virtual environments with a single Python version.
If any of these statements apply to you, I highly recommend pyenv-virtualenv.
Source
pyenv : https://github.com/pyenv/pyenv
pyenv-virtualenv : https://github.com/pyenv/pyenv-virtualenv
For bash (Linux):
- pyenv
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bashrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(pyenv init -)"' >> ~/.bashrc
source ~/.bashrc
- pyenv-virtualenv
git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc
source ~/.bashrc
For zsh (Mac):
- update
brew update
- pyenv
brew install pyenv
echo 'export PYENV_ROOT="${HOME}/.pyenv"' >> ~/.zshrc
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="${PYENV_ROOT}/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
source ~/.zshrc
- pyenv-virtualenv
brew install pyenv-virtualenv
echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.zshrc
source ~/.zshrc
- Check installable Python versions first
pyenv install -l
- Install a Python version
pyenv install <python-version>
An example:
pyenv install 3.10.15
- Check available Python versions
pyenv versions
- Global setting
pyenv global <python-version>
An example:
pyenv global 3.10.15
- Create a virtual environment
pyenv virtualenv <python-version> <env-name>
An example:
pyenv virtualenv 3.10.15 proX
- Check the created virtual environment (just in case)
pyenv versions
- Local setting
mkdir <project-dir>
cd <project-dir>
pyenv local <env-name>
An example:
mkdir projectX
cd projectX
pyenv local proX
- Delete a virtual enviroment (if necessary):
pyenv uninstall <env-name>