I mostly use below python commands in my daily development so this post will be updated frequently.
List all user-installed packages
This command will display all packages installed for the current user.
pip list --user
This will list all user-installed packages in a format suitable for input to pip uninstall
or pip install -r
pip freeze --user
List all packages with locations
pip list --verbose
Package Version Location Installer
------------------ --------- ---------------------------------------------------------------------------- ---------
certifi 2024.8.30 /Users/kenanhancer/.local/lib/python3.12/site-packages pip
charset-normalizer 3.3.2 /Users/kenanhancer/.local/lib/python3.12/site-packages pip
idna 3.10 /Users/kenanhancer/.local/lib/python3.12/site-packages pip
pip 24.2 /Users/kenanhancer/.asdf/installs/python/3.12.5/lib/python3.12/site-packages pip
pipenv 2024.0.3 /Users/kenanhancer/.asdf/installs/python/3.12.5/lib/python3.12/site-packages pip
requests 2.32.3 /Users/kenanhancer/.local/lib/python3.12/site-packages pip
urllib3 2.2.3 /Users/kenanhancer/.local/lib/python3.12/site-packages pip
Find the User Site-Packages Directory
python -m site --user-site
Automated uninstallation of user-installed packages
xargs pip uninstall -y
takes the list and runspip uninstall -y [package]
for each one.
pip freeze --user | xargs pip uninstall -y
pip freeze --user | %{pip uninstall -y $_}
Manual uninstallation of user-installed packages
If you prefer to review the packages before uninstalling:
pip freeze --user > user_packages.txt
xargs -a user_packages.txt pip uninstall -y
Installing a package for specific major and minor version
Installing a package using
--user
option will make it available for all major and minor version.
Assume that i have Python runtimes as3.12.5
and3.12.6
I set global Python runtime as3.12.6
, then i created a project and set Python runtime as3.12.5
if i installpoetry
by runningpip install poetry --user
in Python runtime3.12.5
, it is installed in~/.local/lib/python3.12/site-packages
so it will be available for3.12.x