Installing Python on Mohave with pyenv

How to install Python with pyenv on MacOS Mohave

I use pyenv to manage Python versions on my Mac. I recently have gotten errors like

1
WARNING: The Python sqlite3 extension was not compiled. Missing the SQLite3 lib?

and

1
zipimport.ZipImportError: can't decompress data; zlib not available

The solution seems to be setting LDFLAGS and CPPFLAGS to point to the sqlite3 and zlib libraries, e.g.:

1
2
3
4
5
6
brew install sqlite3
brew install zlib

export LDFLAGS="-L/usr/local/opt/zlib/lib -L/usr/local/opt/sqlite/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include -I/usr/local/opt/sqlite/include"
pyenv install 3.7.0
Last updated on Feb 15, 2024 09:00 -0500
Feedback
FOOTER