Skip to content

Instantly share code, notes, and snippets.

@confluencepoint
Created November 11, 2019 05:25
Show Gist options
  • Select an option

  • Save confluencepoint/f91cf6c98374b808cb3bc43367d2a245 to your computer and use it in GitHub Desktop.

Select an option

Save confluencepoint/f91cf6c98374b808cb3bc43367d2a245 to your computer and use it in GitHub Desktop.

How to setup Python on macOS

Recently, I turned into a big fan of pyenv and poetry for managing my Python installation on macOS. The basic steps are easy but can get tricky.

Setup pyenv and Python

Theses steps assume you have installed Homebrew. But of course you can also install pyenv with its own installer.

brew install pyenv
pyenv install 3.7.5
pyenv global 3.7.5

pyenv needs some initialisation in your shell configuration. Just add the following to your ~/.zshrc or ~/.bashrc and source the config file. (Or if you want a more rustic solution, restart your shell.)

eval "$(pyenv init -)"

After you have done that, pyenv is up and running. Your default Python version is 3.7.5 in your shell.

I normally install some handy tools, too.

pip3 install --upgrade setuptools pip flake8 isort black==19.10b0 pipdeptree ipython requests cookiecutter pre-commit safety

Why 3.7.5?* I still prefer to use a patched stable version over a dotzero release. But I will switch to 3.8.1 as soon as it is available.

Setup poetry

poetry is simply the best tool to manage your dependencies and virtual environments in a project. For me it is the killer app I have been waiting for and finally enjoy releasing Python projects. Until now the whole packaging system of Python has been a mess from my point of view.

Before installing poetry, we have to deactivate our shiny pyenv-powered Python installation and reactivate it afterwards. I also prefer to use the beta versions of poetry at the moment. Very stable and version 1.0.0 is coming soon.

pyenv shell system
curl -O https://raw.githubusercontent.com/sdispater/poetry/master/get-poetry.py
python get-poetry.py --preview
pyenv shell 3.7.5

Now, everything is up and running to enjoy modern Python.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment