2 min read

Setting up Python on macOS Tahoe

macOS Tahoe is an excellent platform for Python development. While the system may include a version of Python for its own use, it is highly recommended to install a separate version for development to avoid conflicting with system tools.

This guide relies on Homebrew for installation. If you haven't set it up yet, please see Package Management with Homebrew on macOS Tahoe.

Installing Python

The easiest way to install the latest version of Python is via Homebrew.

  1. Open your terminal.
  2. Run the installation command:
brew install python
  1. Verify the installation:
python3 --version
pip3 --version

Virtual Environments

It is best practice to use virtual environments for your projects. This keeps dependencies required by different projects separate.

Creating a Virtual Environment

Navigate to your project directory and run:

python3 -m venv venv

This creates a folder named venv in your directory containing a standalone Python installation.

Activating the Environment

To start using the virtual environment:

source venv/bin/activate

Your terminal prompt should now show (venv), indicating that you are working inside the isolated environment.

Deactivating

To exit the virtual environment and return to the global Python context:

deactivate

Managing Packages with Pip

Once your virtual environment is active, you can install packages using pip.

pip install requests

To save your project's dependencies to a file:

pip freeze > requirements.txt

To install dependencies from a file:

pip install -r requirements.txt