On MacOS 14, pip install throws error: externally-managed-environment

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
pstivers3@mbp ~/repos/learn/pythonlearn
$ 
(.venv) 

# Note, you can chose any folder location and name that you want for the venv. ~/.venv is typical.
# Your project code can be in any directory.
3 Likes