pythonpip

Unable to use pip and install requests library


I have python 3.13.1 installed using homebrew 4.4.11 and I am trying to install the requests library on MacOS Sequoia 15.1. This is not making any sense to me.

> python3 --version
python 3.13.1

> which python3
/opt/homebrew/bin/python3

> python3 -m pip --version
pip 24.3.1 from /opt/homebrew/lib/python3.13/site-packages/pip (python 3.13)

> which pip
pip not found

> python3 -m pip install requests
error: externally-managed-environment

> brew install requests
Warning: No available formula with the name "requests"

Solution

  • The HomeBrew installation is marked as "externally managed" to indicate that only Homebrew, not you, should be updating the Python library installed there. Instead of using the installation directly, you should create a virtual environment (either one specific to a project, or just a "global" virtual environment that you can install to separately from Homebrew) and run pip from there.

    >>> python -m venv mypython
    >>> mypython/bin/python -m pip install requests
    

    As far as I can tell, HomeBrew does not provide a formula or cask for the requests library, though as a language-agnostic package manager, such a formula would probably be named python-requests or requests-python to distinguish it from an identically named package for some other language.