Setup a Python Development Environment
This is intended as a quick reference for setting up a Python development environment.
This is intended as a quick reference and explanation of how I setup environments to develop via Python on my Mac.
Requirements
- Develop/test on different versions of Python.
- Isolate each project from each other.
Isolate Python versions
pyenv a simple python version management tool that can be installed via homebrew.
Installalation
brew install pyenv
List installed python versions
pyenv install --list
Load python versions
pyenv install -v 3.8.2
List your loaded python versions
pyenv versions
Change your global python version
pyenv global 3.8.2
Set location specific python version
pyenv local 2.7.15
Uninstall any version
pyenv uninstall 2.7.15
Add to ~/.bash_profile
export PYENV_ROOT="$HOME/.pyenv"
export PATH="$PYENV_ROOT/bin:$PATH"
if command -v pyenv 1>/dev/null 2>&1; then
eval "$(pyenv init -)"
fi
Create a virtual environment
pyenv versions
pyenv shell 3.8.2
python -V
python -m venv env
source env/bin/activate
Leave virtual environment
deactivate