I have accidentally installed Pygame for my system-wide Python (i.e., using pip3
which has path /usr/bin/pip3
). I have read somewhere that it is a good practice to keep system Python clean. I want to remove Pygame and all of its dependencies from my system Python. How can I do that safely?
I find this solution pip3 freeze > to_delete.txt
and pip3 uninstall -y -r to_delete.txt
, but I am afraid to accidentally remove packages that are actually needed by system (like perhaps macholib
which is in my to_delete.txt
).
Is there a way to remove only user-installed packages from system Python on macOS safely?
This pipdeptree package is really helpful to see what is happening with your dependencies:
pip install pipdeptree
to run it once installed:
pipdeptree
Here is an example output:
Django==5.0.2
├── asgiref [required: >=3.7.0,<4, installed: 3.7.2]
└── sqlparse [required: >=0.3.1, installed: 0.4.4]
pip==23.2.1
pipdeptree==2.15.1
pygame==2.5.2
You can see that Django depends on some other packages, but in fact pygame
does not. If your version of pygame also has no dependencies then you should be safe to just:
pip uninstall pygame && pip uninstall pipdeptree