Python Virtual Environment
There is more than one way to skin the cat:
Here we cover pyenv+pyenv-virtualenv on Mac and Linux.
Install pyenv+pyenv-virtualenv on MacOS
brew update
brew install pyenv
echo 'eval "$(pyenv init --path)"' >> ~/.zprofile
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
brew install pyenv-virtualenv
echo 'eval eval "$(pyenv virtualenv-init -)"' >> ~/.zshrc
Install pyenv+pyenv-virtualenv on Linux
curl https://pyenv.run | bash
added this to .zshenv:
# support for pyenv
export PYENV_ROOT="$HOME/.pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"
eval "$(pyenv init -)"
eval "$(pyenv virtualenv-init -)"
Create a Virtual Environment
- create
.python-version
; pyenv
uses python version from.python-version
;pyenv-virtualenv
creates and uses python virtual environment named after.python-version
.
Virtual Environment Maintenance
To see the current dependencies as a table:
pip3 list
To freeze:
pip3 freeze > requirements.txt