How to Start a Python Project
These steps will help you set up and manage a Python environment on macOS, using Homebrew.
Watch how I used Cursor to learn about python environments:
TLDR
Install Python3
If not installed, use your system package manager to install Python3.
Instructions here use Homebrew for macOS.
Create a Virtual Environment with venv
Use any directory name you like.
Activate a Virtual Environment with source
Install Packages with pip
Example: pip install awscli
Generate a requirements.txt
file with pip freeze
The resulting file will look like this:
Deactivate the Virtual Environment
Some prefer virtualenv
over venv
While Python3 comes with venv
by default, some use virtualenv for “additional features” — though I can’t speak directly to the differences.
Additional reading on virtual environments in Homebrew
- https://nicolaiarocci.com/when-homebrew-breaks-your-python-virtual-environment/
- https://stackoverflow.com/questions/25701133/how-to-tell-homebrew-to-install-inside-virtualenv
- https://formulae.brew.sh/formula/virtualenv
- https://github.com/orgs/Homebrew/discussions/4419
- https://discuss.python.org/t/on-macos-14-pip-install-throws-error-externally-managed-environment/50352
- https://gist.github.com/pandafulmanda/730a9355e088a9970b18275cb9eadef3?permalink_comment_id=2809269
- https://courses.cs.washington.edu/courses/cse446/18wi/sections/section1/virtualenv_handout.pdf
- https://www.reddit.com/r/learnpython/comments/xf1pv6/brew_python_and_libraries_installation_blues/