Skip to content

Instantly share code, notes, and snippets.

@ctberthiaume
Last active March 2, 2021 01:27
Show Gist options
  • Save ctberthiaume/c630ea983c8bcde062eea90f016a5e1e to your computer and use it in GitHub Desktop.
Save ctberthiaume/c630ea983c8bcde062eea90f016a5e1e to your computer and use it in GitHub Desktop.
MacOS Python 3 setup with pyenv and poetry, no shims

Install pyenv, but don't use shims and pyenv init to prevent pyenv from intercepting common executables with its shim. e.g. if you have tox installed as a pex standalone executable, but also in a pyenv-managed virtual environment, pyenv will intercept a call to tox.

Install pyenv

Use the pyenv installer with curl https://pyenv.run | bash.

Remove any eval of pyenv init or pyenv virtualenv-init that the installer added to ~/.bash_profile. Keep or add export PATH="$HOME/.pyenv/bin:$PATH" in ~/.bash_profile.

pyenv will only be used to manage installation of different versions of Python. e.g. install Python 3.8.8 with pyenv install 3.8.8. Then add this version's location to your path to make it the default Python.

Restart your shell to update PATH.

Now install poetry.

curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/get-poetry.py | python3

And add poetry bash completions (assuming homebrew on a Mac here):

poetry completions bash > $(brew --prefix)/etc/bash_completion.d/poetry.bash-completion
echo "source $(brew --prefix)/etc/bash_completion.d/poetry.bash-completion" >> ~/.bash_profile

In the end, the cumulative changes to ~/.bash_profile should look like this:

export PATH="$HOME/.pyenv/bin:$PATH"
export PATH="$HOME/.pyenv/versions/3.8.8/bin:$PATH"
export PATH="$HOME/.poetry/bin:$PATH"
source /usr/local/etc/bash_completion.d/poetry.bash-completion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment