# Mac OSX ```bash brew install pyenv openssl readline sqlite3 xz zlib ``` ```bash # optional (venv management is best left to poetry or others) brew install pyenv-virtualenv  pyenv init # set up pyenv ``` ## [Issue on Mac](https://github.com/pyenv/pyenv/issues/544) ```bash ModuleNotFoundError: No module named 'pyexpat' ``` Fixing the issue: ```bash sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.XX.pkg -target / ``` ## `brew` cross-talk Prevent Homebrew from falling for `pyenv`-based Python versions by adding this to your environment: ```shell alias brew='env PATH="${PATH//$(pyenv root)\/shims:/}" brew' ``` # Linux ```bash sudo apt-get install --no-install-recommends make build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev curl https://pyenv.run | bash # optional (venv management is best left to poetry or others) git clone https://github.com/pyenv/pyenv-virtualenv.git $(pyenv root)/plugins/pyenv-virtualenv ``` ## Issue on Linux ```bash pyenv: python: command not found ``` Fix: ```bash sudo update-alternatives --install /usr/bin/python python /usr/bin/python3 10 ``` # Shell Setup ```bash echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_environment echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_environment echo 'eval "$(pyenv init -)"' >> ~/.bash_environemnt ``` # General caveats ## `pyenv rehash` After installing a new executable for which `pyenv` provides a shim (in particular, after installing `pip`, `pip3`, etc., it is necessary to run: ```bash pyenv rehash ``` Otherwise, the wrong pip might get used, and e.g., packages get installed into the system version instead of the newly created pyenv.