ou can create multiple pyenv environments for different Python versions or projects.
AI Python Setup TutorialAI Python Setup Tutorial (Mac)
This tutorial guides you through installing a clean Python AI environment on macOS with Python 3.11 while keeping Python 3.14, and installing the essential AI libraries: PyTorch, Replicate, Diffusers, OpenAI, and Jupyter.
Step 1: Install Homebrew
Homebrew is required to install Python and other tools. Run this in Terminal:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Step 2: Install pyenv
pyenv allows multiple Python versions side-by-side:
brew install pyenv
Tip: Add pyenv to your shell startup if prompted:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init --path)"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
Step 3: Install Python 3.11
pyenv install 3.11.10 -s
Step 4: Create a Virtual Environment
pyenv virtualenv 3.11.10 ai-env
pyenv activate ai-env
Step 5: Upgrade pip
pip install --upgrade pip setuptools wheel
Step 6: Install AI Libraries
pip install torch torchvision torchaudio
pip install replicate
pip install diffusers transformers accelerate
pip install openai
pip install jupyterlab notebook pillow requests user_agents
Step 7: Run Your AI Environment
Activate your environment anytime:
pyenv activate ai-env
Deactivate it:
pyenv deactivate
Run Jupyter:
jupyter lab
Run Python scripts:
python your_script.py
Tips & Notes
- This keeps your macOS Python 3.14 untouched.
- All AI packages are installed inside the
ai-envvirtual environment. - You can create multiple pyenv environments for different Python versions or projects.
Optional: Faster Stable Diffusion
If using a Mac with Apple Silicon, you can enable Metal acceleration for much faster inference. This is optional.