# Install Pyenv & Pyenv-virtualenv ## Install Python build dependencies ```bash xcode-select --install brew install openssl readline sqlite3 xz zlib ``` ## Install using Homebrew ```bash brew update brew install pyenv brew install pyenv-virtualenv ``` ## Set up your shell startup scripts ### If using ZSH (default since OS X 10.15) ```bash echo 'eval "$(pyenv init --path)"' >> ~/.zprofile echo 'eval "$(pyenv init -)"' >> ~/.zshrc echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.zshrc ``` ### If using Bash ```bash echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.profile echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.profile echo 'eval "$(pyenv init --path)"' >> ~/.profile echo 'if [ -n "$PS1" -a -n "$BASH_VERSION" ]; then source ~/.bashrc; fi' >> ~/.profile echo 'eval "$(pyenv init -)"' >> ~/.bashrc echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bashrc ``` You may need to open a new shell after this. --- # Use virtualenvs Each of the below `pyenv ` operations is documented [here](https://github.com/pyenv/pyenv/blob/master/COMMANDS.md) ## Install desried python version(s) ```bash # pyenv install pyenv install 3.7.12 ``` ## Create a virtualenv ```bash # pyenv virtualenv pyenv virtualenv myenv 3.7.12 ``` ## Set a virtualenv as the default for a project/directory This creates a `.python-version` file that tells `pyenv` which executable the `python` command should point to. ```bash # To use a virtualenv: # pyenv local pyenv local myenv # To use a python base interpreter: # pyenv local pyenv local 3.7.12 ``` --- # \[Optional\] Install Starship.rs [starship.rs](https://starship.rs/guide/#%F0%9F%9A%80-installation) displays useful information about your terminal environment, such as the version of Python that's currently active. Your prompt line should then look something like this: ``` tasercake on master [$!] via 🐍 v3.7.12 (myenv) on ☁️ (us-east-1) ❯ ```