24

Can you delete Python modules? I've installed one that I would like to remove, and can't seem to figure out how.

Thanks

informatik01
  • 16,038
  • 10
  • 74
  • 104
Matthew
  • 261
  • 1
  • 2
  • 6
  • 1
    How did you install it in the first place? And which specific module/package was it? And what platform are you on (if that's not going to be obvious after you update your question)? – Peter Hansen Mar 23 '10 at 18:00

4 Answers4

37

To find where the module is, just do a:

 $ python
 >> import module
 >> print module.__file__
 '/some/directory'

or if it is a package:

 >> import package
 >> print package.__path__

and delete it.

rlotun
  • 7,897
  • 4
  • 28
  • 23
18

If you are using python under windows, the following command is what you need

pip uninstall module

In some cases, you may have installed different versions of the module. For example, after I had the lxml3.4.4 installed via pip, I also installed lxml3.5.0 using its pre-built binary, and thus, the command listed above only remove the first one. So I need to run it twices

pip uninstall lxml
pip uninstall lxml

And it got completed uninstalled. See whether it helps.

API
  • 480
  • 3
  • 10
5

This has already been asked here.

Go into the "site-packages" directory of your python install and remove the files manually.

Community
  • 1
  • 1
manifest
  • 2,208
  • 16
  • 13
0

Another way using -m flag (especially if Alex Feng's answer is not working) is:

python -m pip uninstall module

NOTE: This works only for Windows, and is to be run in the Command Prompt. To see if the module has been uninstalled, simply try to import the module again.

CoolCoder
  • 786
  • 7
  • 20