Does pip uninstall modules?

Viewed 217

I checked the installed modules with help("modules")

I've tried uninstalling a module I did not want with pip uninstall somemodule, but I got this warning:

WARNING: Skipping somemodule as it is not installed.

In pip's documentation of pip uninstall it says in the description: Uninstall packages.

However in this answer it says that running pip uninstall somemodule will work.

Question:

  1. Can pip uninstall modules or only packages? I'm very confused.

  2. Will deleting the .py file in its directory, completely uninstall it, or is it a bad practice?

EDIT:

I have 2 versions of python installed. I ran all commands in python 3.9.1

py --version gives Python 3.9.1, and pip --version gives pip 21.0.1 from c:\...\python\python39\lib\site-packages\pip (python 3.9)

I've created a venv at some point. I deleted the folder shortly after creating the venv.

py -m pip uninstall somemodule also did not work

somemodule is the antigravity module that comes with python

1 Answers

With pip you can install or uninstall distribution packages. These may contain any number of packages, modules or resource files. The antigravity module however is part of the standard library and hence cannot be removed by pip. If you really want to remove that module, you can identify its location in the following way and then remove it manually:

>>> import antigravity
>>> antigravity.__file__
'/path/to/lib/python3.9/antigravity.py'
$ rm lib/python3.9/antigravity.py

You can get a list of installed distributions via pip freeze and these are the ones you can remove as well. Note that sometimes the distribution name and the name of the top-level package that you import are not the same (e.g. you would do pip install scikit-learn and then import sklearn).

Related