1 from __future__ import absolute_import
4 from pip.wheel import WheelCache
5 from pip.req import InstallRequirement, RequirementSet, parse_requirements
6 from pip.basecommand import Command
7 from pip.exceptions import InstallationError
10 class UninstallCommand(Command):
14 pip is able to uninstall most installed packages. Known exceptions are:
16 - Pure distutils packages installed with ``python setup.py install``, which
17 leave behind no metadata to determine what files were installed.
18 - Script wrappers installed by ``python setup.py develop``.
22 %prog [options] <package> ...
23 %prog [options] -r <requirements file> ..."""
24 summary = 'Uninstall packages.'
26 def __init__(self, *args, **kw):
27 super(UninstallCommand, self).__init__(*args, **kw)
28 self.cmd_opts.add_option(
29 '-r', '--requirement',
34 help='Uninstall all the packages listed in the given requirements '
35 'file. This option can be used multiple times.',
37 self.cmd_opts.add_option(
41 help="Don't ask for confirmation of uninstall deletions.")
43 self.parser.insert_option_group(0, self.cmd_opts)
45 def run(self, options, args):
46 with self._build_session(options) as session:
47 format_control = pip.index.FormatControl(set(), set())
48 wheel_cache = WheelCache(options.cache_dir, format_control)
49 requirement_set = RequirementSet(
53 isolated=options.isolated_mode,
55 wheel_cache=wheel_cache,
58 requirement_set.add_requirement(
59 InstallRequirement.from_line(
60 name, isolated=options.isolated_mode,
61 wheel_cache=wheel_cache
64 for filename in options.requirements:
65 for req in parse_requirements(
69 wheel_cache=wheel_cache):
70 requirement_set.add_requirement(req)
71 if not requirement_set.has_requirements:
72 raise InstallationError(
73 'You must give at least one requirement to %(name)s (see '
74 '"pip help %(name)s")' % dict(name=self.name)
76 requirement_set.uninstall(auto_confirm=options.yes)