In my last post, I walked through setting up my new Mac Mini M4 for a modern, efficient, and zenful development experience. Now, let’s take it a step further by equipping your Mac with the essential Python prerequisites for AI-related work. As always, we’ll stick to XDG standards where possible, ensuring a clean and organized environment.
Step 1: Install pyenv for Python Version Management
Python version management is crucial for AI development. We’ll use pyenv to manage Python installations.
brew install pyenvSet up pyenv to be XDG-compliant.
mkdir -p $XDG_DATA_HOME/pyenvAdd the following lines to your ~/.zshenv and ~/.zshrc file:
export PYENV_ROOT="$XDG_DATA_HOME/pyenv"
[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"eval "$(pyenv init -)"Step 2: Configure pip to Follow XDG Standards
To keep things organized, configure pip to use XDG directories.
mkdir -p $XDG_CACHE_HOME/pip
mkdir -p $XDG_CONFIG_HOME/pipAdd the following lines to ~/.zshenv:
export PIP_CACHE_DIR="$XDG_CACHE_HOME/pip"
export PIP_CONFIG_FILE="$XDG_CONFIG_HOME/pip/pip.conf"Step 3: Install Python 3.11
Python 3.11 is currently optimal for AI work as of March 2025. Install and set it as the global version.
pyenv install 3.11.11
pyenv global 3.11.11Verify the installation:
python --versionUpdate pip to the latest version:
python -m pip install --upgrade pipStep 3: Install Pipx
Install pipx for installing Python tools in isolated environments:
python -m pip install --user pipx
mkdir -p $XDG_DATA_HOME/pipxAdd the following lines to ~/.zshenv:
export PIPX_HOME="$XDG_DATA_HOME/pipx"
export PIPX_BIN_DIR="$XDG_BIN_HOME"Ensure directory where pipx stores apps:
python -m pipx ensurepathInstall virtualenv for environment management:
pip install virtualenvInstall pipx for isolated command-line applications:
pip install pipx
pipx ensurepathStep 4: Create a Virtual Environment for AI Development
Keeping AI projects in an isolated virtual environment is a best practice.
mkdir -p $XDG_DATA_HOME/virtualenvs
python -m venv $XDG_DATA_HOME/virtualenvs/aiTo set up an alias for quick activation, add this line to ~/.zaliases:
alias ai-dev="source $XDG_DATA_HOME/virtualenvs/ai/bin/activate"Now you can activate the environment by running:
aiUpdate pip for the environment:
python -m pip install --upgrade pipDeactivate the environment:
deactivate
