Managing and installing pip3 modules with venv and requirements.txt on MacOS

External python dependencies can be installed with pip, and managed as a list of dependencies for your project with a requirements.txt file. To install dependencies for a project, use:

> python3 -m pip install -r requirements.txt

On MacOS, it’s no longer possible to install global modules, unless you force the install with the ‘–break-system-packages’ option, if you pip like above, you’ll see the error:

error: externally-managed-environment
× This environment is externally managed

Instead, create a virtual environment for your project where dependencies local to your project are installed:

> python3 -m venv .venv
> source .venv/bin/activate

Now you can run pip install and all dependent modules will be installed beneath .venv in your project folder.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.