def uninstall(*package_names): """ Uninstall one or more packages using the Python equivalent of ``pip uninstall --yes``. The package(s) to uninstall must be installed, otherwise pip will raise an ``UninstallationError``. You can check for installed packages using :func:`is_installed()`. :param package_names: The names of one or more Python packages (strings). """ command = UninstallCommand() opts, args = command.parse_args(['--yes'] + list(package_names)) command.run(opts, args)
def uninstall(*package_names): """ Uninstall one or more packages using the Python equivalent of ``pip uninstall --yes``. The package(s) to uninstall must be installed, otherwise pip will raise an ``UninstallationError``. You can check for installed packages using :func:`is_installed()`. :param package_names: The names of one or more Python packages (strings). """ command = UninstallCommand() opts, args = command.parse_args(['--yes'] + list(package_names)) command.run(opts, args)
def remove_package(self, packages): uninstall = UninstallCommand() pkg_list = packages.split(" ") for pkg in pkg_list: options, args = uninstall.parse_args([pkg, '--y']) uninstall.run(options, args)
installed_packages = [ package.project_name for package in get_installed_distributions() if (not package.location.endswith('dist-packages') and package.project_name not in ('pip', 'setuptools')) ] if installed_packages: pip = UninstallCommand() options, args = pip.parse_args(installed_packages) options.yes = True try: pip.run(options, args) except OSError as e: if e.errno != 13: raise e print("You lack permissions to uninstall this package. Perhaps run with sudo? Exiting.") exit(13) date = parse_iso8601(sys.argv[1]) packages = {p: select_version(date, p) for p in sys.argv[2:]} args = ['=='.join(a) for a in packages.items()] cmd = InstallCommand() options, args = cmd.parse_args(args) options.ignore_installed = True options.force_reinstall = True
def remove_package(self, packages): uninstall = UninstallCommand() pkg_list = packages.split(" ") for pkg in pkg_list: options, args = uninstall.parse_args([pkg, '--y']) uninstall.run(options, args)
#!/usr/bin/env python from __future__ import print_function from pip.commands.uninstall import UninstallCommand from pip import get_installed_distributions packages = [] for package in get_installed_distributions(): if package.location.endswith('dist-packages'): continue elif package.project_name in ('pip', 'setuptools'): continue packages.append(package.project_name) if packages: pip = UninstallCommand() options, args = pip.parse_args(packages) options.yes = True try: pip.run(options, args) except OSError as e: if e.errno != 13: raise e print("You lack permissions to uninstall this package. Perhaps run with sudo? Exiting.") exit(13)
#!/usr/bin/env python from sys import stderr from pip.commands.uninstall import UninstallCommand from pip import get_installed_distributions pip_uninstall = UninstallCommand() options, args = pip_uninstall.parse_args([ package.project_name for package in get_installed_distributions() if not package.location.endswith('dist-packages') ]) options.yes = True # Don't confirm before uninstall # set `options.require_venv` to True for virtualenv restriction try: print pip_uninstall.run(options, args) except OSError as e: if e.errno != 13: raise e print >> stderr, "You lack permissions to uninstall this package. Perhaps run with sudo? Exiting." exit(13) # Plenty of other exceptions can be thrown, e.g.: `InstallationError` # handle them if you want to.