On MacOS 14, pip install throws error: externally-managed-environment.
What’s the best way to resolve? My background and exploration so far.
I’m a recently retired devops engineer. Mostly used bash and DSLs on the job plus dabbled in Python, Ruby, Go. Now wanting to really learn Python. Working through the Harvard CS50p python and then CS50 AI using python classes, plus the book Learning Python, Lutz.
Running a Mac M2 with MacOS 14. Chose to install both vim and python3 with homebrew. (I don’t explicitly remember that but they show up in brew list and I’ve read that python3 doesn’t come preinstalled since at least Ventura.) Homebrew seems to have maybe been a bad decision.
As soon as I tried pip install…
$ python3 -m pip install requests # or any other module
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.
I did google about this for over an hour plus read
https://github.com/python/cpython/issues/102134#issuecomment-1445428402
https://discuss.python.org/t/right-or-best-way-to-install-python-in-macos-10-15-catalina/6204
Earlier I thought, maybe brew uninstall python3 and install it another way but…
$ brew uninstall python3
Error: Refusing to uninstall /opt/homebrew/Cellar/python@3.12/3.12.2_1
because it is required by vim, which is currently installed.
You can override this and force removal with:
brew uninstall --ignore-dependencies python3
$ brew list | grep vim
vim
I haven’t yet tested brew uninstall vim. I don’t know if it will promt me or just uninstall it, or if I’ll get yet more dependencies.
Then I thought maybe I’ll install requests with brew but…
https://formulae.brew.sh/formula/python-requests is deprecated
My question is how best to preceed from here for a stable platform for installing other python modules on MacOS 14. I’m starting to think that venv or pipx is a good idea in any event. Not sure if I should bother trying to brew uninstall vim and python 3.
Thoughts on best combination of solutions?
-
Try brew uninstall vim and then uninstall python3. Then install them another way? Assumes I don’t get more warnings when brew uninstall vim.
-
brew install pipx and use pipx?
-
brew install vitualenv and use that? Assumes that’s the same as venv.
-
Other?