Workflow:
- Download the binary of a desired python version
- Create a virtual environment that uses the desired python binary
# List all available versions
pyenv install --list
# Install a specific version
pyenv install 3.8.9
# Set it globally
pyenv global 3.8.9
# Verify it's correct
which python
# /Users/jlam/.pyenv/shims/python
python --version
# Python 3.8.9
# Required: Install virtualenvwrapper so that pyenv-virtualenvwrapper works
pip install virtualenvwrapper
To install python3.6 (or others) on Ubuntu 20.04 LTS:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.6
# Search for available versions
brew search python
# Executable will be in /usr/local/opt/python@3.7/bin/python3
brew install python@3.7
A thin wrapper around virtualenv that installs all envs in ~/.virtualenv
and makes it easier to manage/switch between environments.
# Make a new environment
mkvirtualenv myenv
# Specify a specific python version
mkvirtualenv myenv -p /path/to/bin/python
# Delete an environment
rmvirtualenv myenv
# List the available environments
lsvirtualenv
# Select an environment to use
workon myenv
# Or use the dot if the env name matches the current directory's name (e.g. cd ~/src/myproj; workon myproj)
workon .
virtualenv myenv
# on Windows
source myenv/Scripts/activate
# on Linux
source myenv/bin/activate
For conda > 4.6.7:
# List environments
conda env list
# Create new virtual environment with the current python version
conda create -n myenv python
# Or with a specific python version
conda create -n myenv python=3.6
# Activate env
conda activate myenv
# Deactivate env
conda deactivate
# Remove environment
conda remove --name myenv --all
# Remove environment (alternative command if previous doesn't work
conda env remove --name myenv