This document serves as a quick overview for setting up a new M1 Mac for Python based development.
-
Install Docker Desktop https://www.docker.com/products/docker-desktop/
-
Install xcode command line tools
xcode-select --install
- Install Homebrew (https://brew.sh)
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Install pyenv
# Install python build deps
brew install openssl readline sqlite3 xz zlib tcl-tk
brew install pyenv
Add this to your .bashrc
or .zshrc
(at the very end)
export PYENV_ROOT="$HOME/.pyenv"
eval "$(pyenv init -)"
For more details, see here: https://github.com/pyenv/pyenv#set-up-your-shell-environment-for-pyenv
- Install the latest python version (at the time of writing,
3.10.6
) via pyenv
pyenv install 3.10.6
- Install Python Tools
pip3 install --upgrade pip
pip3 install --user poetry # https://python-poetry.org
# Setup deps. for PG related tools (psycopg2)
brew install libpq --build-from-source
brew install openssl
# Add to your .bashrc / .zshrc
export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib -L/opt/homebrew/opt/libpq/lib"
export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include -I/opt/homebrew/opt/libpq/include"
pip3 install --user pgcli # https://github.com/dbcli/pgcli
- Install latest
git
brew install git
- Instal NodeJS (LTS)
brew install node@16
# Allow npm packages to be installed globally without sudo
# See: https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
- Upgrade to the latest Bash and set it as your default shell.
brew install bash
sudo echo "/opt/homebrew/bin/bash" >> /etc/shells
chsh -s /opt/homebrew/bin/bash
Install + Setup bash-completion
# Since we're using Bash 5+, remove old completions and install the v2 version
# which is recommended for new Bash versions
brew unlink bash-completion
brew install bash-completion@2
brew link bash-completion@2 # in case it wasn't linked already.
Add the folliowing to your .bashrc
(after PATH
is set):
[[ -r "$(brew --prefix)/etc/profile.d/bash_completion.sh" ]] && . "$(brew --prefix)/etc/profile.d/bash_completion.sh"
See below for sample .bashrc
- Nice to have tools and utils.
brew install wget
brew install htop
brew install tree
brew install coreutils
brew install jq # https://github.com/stedolan/jq
brew install fzf # https://github.com/junegunn/fzf
brew install exa # https://github.com/ogham/exa
brew install --cask rectangle # https://github.com/rxhanson/Rectangle
brew install --cask unnaturalscrollwheels # https://github.com/ther0n/UnnaturalScrollWheels
- Development tools to install manually
- Sublime Merge / Git Kraken
- Pycharm, IntelliJ IDEA, DataGrip, WebStrom
- VS Code / Sublime Text
- Postman / Insomnia
# Enable command history (up/down arrow keys)
bind '"\e[A":history-search-backward'
bind '"\e[B":history-search-forward'
bind 'set show-all-if-ambiguous on'
# bind 'set completion-ignore-case on'
# Setup Prompt
# ---
darkgrey='\[\033[01;38;5;244m\]'
grey='\[\033[01;38;5;248m\]'
yellow='\[\033[01;38;5;185m\]'
reset='\[\033[0m\]'
gitbranchname() {
branchname=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
if [ ! -z "$branchname" ]
then
echo "($branchname) "
fi
}
export PS1="$darkgrey\h $grey[\w]$yellow \$(gitbranchname)\$$reset "
# ---
# Aliases
# ---------------
alias ls='exa -aF'
alias ll='exa -a --long --classify --group-directories-first --color-scale --header'
# Env. Vars.
# ---------------
export PIPENV_VENV_IN_PROJECT=true
# Work
export DKR_REGISTRY="<registry_id>.dkr.ecr.us-east-1.amazonaws.com"
export JFROG_USER=""
export JFROG_PASSWORD=""
export PIP_EXTRA_INDEX_URL=https://<username>:<password>@<company_name>.jfrog.io/<company_name>/api/pypi/pypi-local/simple
# Update PATH
# ---------------
PATH="/Users/<username>/Library/Python/3.8/bin:$PATH"
PATH="~/bin:/opt/homebrew/bin:$PATH"
PATH="~/.npm-global/bin:$PATH"
PATH="/opt/homebrew/opt/libpq/bin:$PATH"
# Add Coreutils to path
export PATH=$(brew --prefix coreutils)/libexec/gnubin:$PATH
export MANPATH=$(brew --prefix coreutils)/libexec/gnuman:$MANPATH
# ---
export LDFLAGS="-L/opt/homebrew/opt/[email protected]/lib -L/opt/homebrew/opt/libpq/lib"
export CPPFLAGS="-I/opt/homebrew/opt/[email protected]/include -I/opt/homebrew/opt/libpq/include"
# Enable bash-completion (install bash-completion v2 first)
[[ -r "$(brew --prefix)/etc/profile.d/bash_completion.sh" ]] && . "$(brew --prefix)/etc/profile.d/bash_completion.sh"
# Enable pyenv
export PYENV_ROOT="$HOME/.pyenv"
eval "$(pyenv init -)"