Symptoms
I attempted to install a Python package using this command.
pip3 install [package-name]
And then this error was thrown.
Description
- Two types of Python are used in a single MacOS machine - User-specific and System-wide packages.
- System-wide packages are shared by all the users, and even system package managers like apt. Installing user-specific packages as system-wide packages is very dangerous because it can conflict with system package managers if they run some Python scripts.
Solution
-
Create
~/.config/pip/pip.conf
and type this script.
[install] break-system-packages = true user = true
-
Install
pipenv
to manage dependencies per project. Thepip.conf
file lets the command run with--break-system-packages
and--user
options. Otherwise,pipenv
can't install some dependencies since the python packages require a certain python version.
pip3 install pipenv which python3.13 pipenv --python /opt/homebrew/bin/python3.13(directory of python)
-
If you're using zsh, add the directory of python to the PATH. Make sure the version is set explictly! Otherwise, pipenv command won't be found.
export PATH="$HOME/Library/Python/3.13/bin:$PATH" # This loads python
-
Run a file with the all project dependencies in a virtual environment
pipenv run python [file-name] .py
-
Otherwise, you could run up a virtual environment instance and run the python file.
pipenv shell python [file-name].py
Top comments (0)