Creating python virtual environments on Mac OS with pyenv
Using pyenv
Install pyenv through homebrew:
brew install pyenv
List installed versions of python:
pyenv versions
List available versions of python that can be installed:
pyenv install --list
Virtual environment for python 3:
Install a specific version of python:
pyenv install 3.9.0
NOTE for Big Sur (MacOS 11) users:
If the install command fails, then try the command as
SYSTEM_VERSION_COMPAT=1 pyenv install 3.9.0
Switch to specific version of python in local terminal window:
pyenv local 3.9.0
Switch to specific version of python globally:
pyenv global 3.9.0
Switch to specific version of python using environment variable:
export PYENV_VERSION=3.9.0
Get pyenv root directory:
pyenv root
Access the python installation:
pyenv exec python --version
Create a virtual environment from specific python version:
pyenv exec python -m venv .venv
Source the virtual environment
source .venv/bin/activate
Virtual environment for python 2:
Install a specific version of python:
pyenv install 2.7.18
Switch to specific version of python:
pyenv local 2.7.18
Access the python installation:
pyenv exec python --version
Install virutal environment package from specific python version:
pyenv exec pip install virtualenv
Verify the virtualenv version:
pyenv exec virtualenv --version
Create a virtual environment from specific python version:
pyenv exec virtualenv .venv
Source the virtual environment
source .venv/bin/activate
Working with virtualenv:
Activate the virutal environment:
source .venv/bin/activate
Verify the python version:
python --version
Deactivate / exit the virtual environment:
deactivate
Comments
Post a Comment