Of course. You are right, integrating updates can make a guide confusing. Here is a clean, unified, and concise guide from start to finish.
This is the complete, modern workflow for setting up a professional Python development environment on an Apple Silicon Mac.
The Philosophy¶
- Isolate Everything: Never use the system Python. Every project gets its own Python version and its own libraries.
- Automate Quality: Use tools to format and check your code automatically.
- Control Every Change: Use Git for version control from the very first line of code.
Part 1: One-Time System Setup¶
You only need to do this part once.
Step 1: Install Developer Tools Install Apple's essential compilers and Git. Open the Terminal and run:
Step 2: Install Homebrew Get the essential package manager for macOS:
After it finishes, run the two commands it tells you to. This adds Homebrew to your PATH.Step 3: Install and Configure pyenv
Install the best tool for managing multiple Python versions:
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zshrc
echo 'eval "$(pyenv init -)"' >> ~/.zshrc
Step 4: Install Python
Use pyenv to install a recent, clean version of Python and set it as your default:
# Install Python (this will take a few minutes)
pyenv install 3.12.0
# Set this version as your global default
pyenv global 3.12.0
Step 5: Configure Git Tell Git who you are. This name and email will be attached to all your commits.
git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"
git config --global init.defaultBranch main
Step 6: Install VS Code and Extensions
1. Download and install Visual Studio Code from the official website.
2. Open VS Code. Press Cmd + Shift + P, type Shell Command, and select "Shell Command: Install 'code' command in PATH".
3. Go to the Extensions tab (the icon with four squares) and install these two extensions:
* Python (from Microsoft)
* Ruff (from Astral Software)
Your system is now fully prepared.
Part 2: The Per-Project Workflow¶
Follow these steps every time you start a new project.
Step 1: Create Project & Initialize Git
# Create a folder and move into it
mkdir my-project
cd my-project
# Initialize it as a Git repository
git init
Step 2: Create a .gitignore File
This is the most important step for clean version control. Create a file named .gitignore and add the following content to it. This tells Git to ignore temporary files and secrets.
Step 3: Create a Virtual Environment
Isolate your project's dependencies in a local .venv folder.
Step 4: Activate Environment & Install Packages Activate the environment to start using it.
Your terminal prompt will now start with(.venv). Now, you can install libraries, and they will only be installed for this specific project.
Step 5: Make Your First Commit Save the initial state of your project.```bash
Save a list of your dependencies¶
pip freeze > requirements.txt
Add all project files to Git¶
git add .
Save a snapshot of your project with a message¶
git commit -m "Initial commit: Set up project structure and dependencies"
VS Code will automatically detect your.venv virtual environment. Now you can create your Python files (e.g., main.py).
To automate code formatting, create a .vscode folder with a settings.json file inside it and add: