pip list --user
lists only packages installed in your user space, that is, the packages in $HOME/.local/lib/python3.x/site-packages
. The fact that you have none means that you haven’t used pip install --user
to install any packages. But that’s a fairly different thing than how your question started out.
As far as packages in /usr/lib*/python3.10/site-packages/
, while you can use pip
to examine those, you shouldn’t use pip
to manage them at all, because those packages are under the control of rpm
. (By the same token, you should never sudo pip install ____
anything, as you’ll be messing up the system-controlled package collection.)
Pip does have a --not-required
flag to list
, which will exclude packages that are required by another package. However, most of the packages in /usr/lib*/python3.x/site-packages/
will show up as not-required, because they aren’t required by another Python package… that doesn’t mean they aren’t required by one or more RPMs. Again, pip
isn’t really the tool for managing the system package collection.
Note, also, that dnf repoquery --userinstalled
doesn’t completely mean what it appears to. Packages are automatically marked as “user installed” by dnf
if they were installed by direct request of the user, and not marked if they were pulled in as dependencies. But any package can be marked as user-installed by running sudo dnf mark install <package>
, and any package can be marked as non-user-installed by running sudo dnf mark remove <package>
.
Those flags are used by the dnf autoremove
system, which ignores any package listed as user-installed (along with any package that’s a dependency of another package) when computing which packages can be autoremoved.
If you wanted to remove all packages that aren’t required by another package from /usr/lib*/python3.x/site-packages
, the easiest way would be to run sudo dnf mark remove python3-\*
– that will unmark ALL Python RPMs as being user-installed, which means that any which aren’t required by another RPM will now be on the autoremove
chopping block. (You can see what’s auto-removable by running sudo dnf list autoremove
, and remove them with sudo dnf autoremove
.)
Pip doesn’t have a concept of “user-installed” vs. not, because every package is user-installed as far as pip is concerned. The “system” package collection is totally a construct of the RPM packaging system, which is why those packages should be managed the same way.