Let's setup Python with the latest and greatest tools for your macOS developer environment!
Many folks seem to still be installing Python from the download links on the website and installing dependencies with requirements.txt
.
The first thing we need to do is setup the C dependencies for macOS. We'll need to use the tool xcode-select
. This tool installs the minimal dependencies from Xcode to do C style development on macOS. CPython (the standard Python you'll be using, there are others!) relies on having specific macOS C dependencies which xcode-select
will install on your system.
Install via:
Homebrew is the most widely used 3rd party package manager for macOS and we'll use this to install and manage external tools!
Install via:
Remember, the Python installed on macOS is not the most up to date and will even be removed in future macOS releases!
You'll use Pyenv to install the latest and greatest version of Python and set that to your system default.
Install via:
Then setup pyenv
to work with zsh
:
Install Python:
Set the new version as your System Default:
Verify the install with:
Python makes use of a package manager called pip
. This can install tools for your system or dependencies when building your projects! Many Python Packages are hosted on PyPi. Other packages can come from Git repostiories or your local filesystem.
Verify you have the latest and greatest pip:
You may remember using requirements.txt
and setup.py
. These were the old ways of managing Python project's. Those tools are a thing of the past (and have been since May 2016!!!!).
The old way of managing dependencies lead to many mismatched versions betweened developers own machines and production.
Lockfiles were introduced to solve this problem in many ecosystems, and the Python community had to create 3rd party tools to create these.
Lock files pin the exact versions of dependencies used in your project. This means that when you install dependencies, you will get the exact same versions as your teammates and have consistent production builds.
Today we use pyproject.toml
to know what Python dependencies our project relies on. Read more about pyproject.toml here.
Poetry is a tool to manage your Python projects. Together with pyproject.toml
, Poetry handles creation of virtualenv
's, installing production and development deps, create poetry.lock
files, hold package info, build and push packages, and hold tooling config. It feels very similar to how npm
, package.json
, and package-lock.json
work for Node based projects!
There are a few ways to install Poetry but we will actually install it to the currently installed Python version's global pip
packages!
Install poetry via:
Now that your system is configured to do development with Python, let's make a new project!
Now get to building!
For times you want to make a virtual environment not managed by Poetry, remember it comes bundled into Python! And you have the latest Python!
The command virtualenv
is no longer required for use or to install.
Please create virtualenv
's via: