728x90
pip3 install -r requirements.txt
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try brew install
xyz, where xyz is the package you are trying to
install.
If you wish to install a non-brew-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip.
If you wish to install a non-brew packaged Python application,
it may be easiest to use pipx install xyz, which will manage a
virtual environment for you. Make sure you have pipx installed.
note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.
https://discuss.python.org/t/on-macos-14-pip-install-throws-error-externally-managed-environment/50352/6
Homebrew wants you to create a virtual env so that pip-installed modules don’t break something in your system. Same is true if working with python installed by apt-get in Ubuntu for same reason. The package makers have gone to warning us not to pip install python modules in the system (OS) because it’s so often that something will break because of version dependency clashes.
venv has worked great for me and is simple. Here’s a couple references and exactly now I installed it and use it.
References…
https://docs.python.org/3/library/venv.html
https://www.studytonight.com/post/python-virtual-environment-setup-on-mac-osx-easiest-way
Here’s what I did…
mkdir ~/.venv
python3 -m venv ~/.venv
# Creates the following in ~/.venv
# bin/
# include/
# lib/
# pyvenv.cfg
# does not create pip-selfcheck.json
# to activate the venv
source ~/.venv/bin/activate
# now you can..
python3 -m pip install <module name>
# and it will install the module in the virtual env
# to deactivate the venv
deactivate # or exit the shell
# you should see the folder name for the venv below your prompt when active, like so