Table of Contents
Open Table of Contents
🚀 Overview
This guide will walk you through installing Python on your Mac using Homebrew, pyenv, and Poetry. This setup is recommended for development in our project.
📋 Prerequisites
- 
A MacBook running macOS
 - 
Administrator access to your machine
 - 
Internet connection
 
🍺 Step 1: Install Homebrew
- 
Open Terminal (Applications > Utilities > Terminal)
 - 
Install Homebrew:
 
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- 
Follow the prompts in Terminal
 - 
Add Homebrew to your PATH:
 
To determine which shell you’re using, run:
echo $SHELL
- 
If you’re using Zsh (default on newer macOS versions):
 
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zshrc
- 
If you’re using Bash:
 
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.bash_profile
After adding the line, run:
source ~/.zshrc # for Zsh
# or
source ~/.bash_profile # for Bash
- 
Verify installation:
 
brew --version
🔧 Step 2: Install pyenv
- 
Install pyenv:
 
brew install pyenv
- 
Add pyenv to your shell:
 
For Zsh:
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
For Bash:
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.bash_profile
echo 'command -v pyenv >/dev/null || export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
- 
Restart your terminal or run:
 
source ~/.zshrc # for Zsh
# or
source ~/.bash_profile # for Bash
🐍 Step 3: Install Python
- 
Install Python (e.g., 3.11.2):
 
pyenv install 3.11.2
- 
Set as global version:
 
pyenv global 3.11.2
- 
Verify installation:
 
python --version
📦 Step 4: Install Poetry
- 
Install Poetry:
 
curl -sSL https://install.python-poetry.org | python3 -
- 
Add Poetry to your PATH:
 
For Zsh:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc
For Bash:
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bash_profile
source ~/.bash_profile
- 
Verify installation:
 
poetry --version
- 
Configure Poetry:
 
poetry config virtualenvs.in-project true
This setting ensures that Poetry creates virtual environments within your project directory.
🚀 Step 5: Create a New Project
- 
Create a project directory:
 
mkdir my_project
cd my_project
- 
Initialize a new Poetry project:
 
poetry init
- 
Add dependencies:
 
poetry add package_name
- 
Create a virtual environment and install dependencies:
 
poetry install
- 
Activate the virtual environment:
 
poetry shell
🖥️ IDE Setup
While our team primarily uses PyCharm, this guide is IDE-agnostic. Here’s how to set up your preferred IDE with Poetry:
PyCharm
- 
Open your project in PyCharm
 - 
Go to Preferences/Settings > Project > Python Interpreter
 - 
Click the gear icon and select “Add”
 - 
Choose “Poetry Environment”
 - 
Select the existing environment in your project folder (usually
.venv) 
Visual Studio Code
- 
Install the Python extension
 - 
Open your project folder
 - 
Press Cmd+Shift+P and type “Python: Select Interpreter”
 - 
Choose the Poetry environment (usually
.venv/bin/python) 
Cursor.sh
- 
Open your project in Cursor
 - 
Go to Settings > Python > Python Path
 - 
Set it to the path of your Poetry virtual environment (e.g.,
/path/to/your/project/.venv/bin/python) 
Remember to always activate your Poetry environment before running your project:
poetry shell
🔄 Maintenance and Updates
- 
Update pyenv:
brew upgrade pyenv - 
Update Poetry:
poetry self update - 
Update Python:
pyenv install <new_version> && pyenv global <new_version> - 
Update project dependencies:
poetry update 
For more information, refer to:
This guide combines information from multiple sources, including Stack Overflow discussions and Dataquest’s Python Installation Tutorial.