Fixing Python zlib errors in macOS Mojave Beta

Just leaving this here for my own sake, after having to deal with these annoying issues on the macOS Mojave Beta. When trying to build various Homebrew apps that use Python (or are Python) I ran into something like this:

Traceback (most recent call last):
File "/usr/local/bin/pip3", line 11, in
load_entry_point('pip==10.0.1', 'console_scripts', 'pip3')()
File "/usr/local/lib/python3.6/site-packages/pkg_resources/", line 476, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/local/lib/python3.6/site-packages/pkg_resources/", line 2700, in load_entry_point
return ep.load()
File "/usr/local/lib/python3.6/site-packages/pkg_resources/", line 2318, in load
return self.resolve()
File "/usr/local/lib/python3.6/site-packages/pkg_resources/", line 2324, in resolve
module = __import__(self.module_name, fromlist=['__name__'], level=0)
File "/usr/local/lib/python3.6/site-packages/pip/_internal/", line 20, in
from pip._vendor.urllib3.exceptions import DependencyWarning
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/urllib3/", line 8, in
from .connectionpool import (
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/urllib3/", line 36, in
from .response import HTTPResponse
File "/usr/local/lib/python3.6/site-packages/pip/_vendor/urllib3/", line 3, in
import zlib
ModuleNotFoundError: No module named 'zlib'

The fix is as follows, thanks to sfdye over at GitHub:
$ brew update
# (Re)Install CLT (command in one line):
$ sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

Then reinstall your Homebrew Python version with something like
$ brew reinstall python@2

That stopped these zlib errors for me.