Skip to content

Instantly share code, notes, and snippets.

@richardcornish
Last active October 5, 2023 01:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save richardcornish/17e95e3d48689d04b6ea1cc04e09c6f2 to your computer and use it in GitHub Desktop.
Save richardcornish/17e95e3d48689d04b6ea1cc04e09c6f2 to your computer and use it in GitHub Desktop.
Build and install Python and configuration options with pyenv

Install Xcode Command Line Tools.

xcode-select --install

Install Homebrew.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Install Git.

brew install git
git config --list
git config --global user.name "My Name"
git config --global user.email "email@example.com"
git config --global color.ui true

Install SQLite.

brew install sqlite
echo 'export PATH="/usr/local/opt/sqlite/bin:$PATH"' >> ~/.zshrc

Install PostgreSQL.

brew install postgresql@16
echo 'export PATH="/usr/local/opt/postgresql@16/bin:$PATH"' >> ~/.zshrc

Install pyenv.

curl https://pyenv.run | bash
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
exec "$SHELL"

Install Python build dependencies.

brew install openssl readline sqlite3 xz zlib tcl-tk

Build and install Python on macOS with configuration options. See #333 for troubleshooting.

brew install pkg-config openssl@3.0 xz gdbm tcl-tk
env \
    LDFLAGS="-L/usr/local/opt/sqlite/lib -L/usr/local/opt/postgresql@16/lib" \
    CPPFLAGS="-I/usr/local/opt/sqlite/include -I/usr/local/opt/postgresql@16/include" \
    GDBM_CFLAGS="-I$(brew --prefix gdbm)/include" \
    GDBM_LIBS="-L$(brew --prefix gdbm)/lib -lgdbm" \
    PYTHON_CONFIGURE_OPTS="--with-pydebug --with-openssl=$(brew --prefix openssl@3.0)" \
    pyenv install 3.12.0
pyenv global 3.12.0

Install Django.

mkdir myproject && cd myproject/
python -m venv venv
source venv/bin/activate
pip install --upgrade pip django
django-admin startproject myproject
python myproject/manage.py migrate
python myproject/manage.py runserver
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment