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): # type: (str) -> int packages = packages.split() assert packages, "`packages` should not be an empty string." try: # For pip <= 19.1.1 uninstall = UninstallCommand() except TypeError: # For pip > 19.1.1 uninstall = UninstallCommand( "Pippel", "Backend server for the Pippel service.") k = uninstall.main(packages + ["--yes"]) return k
def removePackage(packageName, maxAttempts=10): """ Attempt to gracefully uninstall package with pip, followed by a an eager approach to remove vestiges of namespace packages and previous installations """ UninstallCommand().main( [packageName, "--yes", "--disable-pip-version-check"]) # Remove vestiges of namespace packages, and other previous installations for path in sys.path: for filename in glob.glob(os.path.join(path, packageName + "*")): print "Removing {}".format(filename) if os.path.isdir(filename): shutil.rmtree(filename) else: os.unlink(filename)
def uninstall(params): """ Uninstall third-party Mod """ from pip import main as pip_main from pip.commands.uninstall import UninstallCommand params = [param for param in params] options, mod_list = UninstallCommand().parse_args(params) params = ["uninstall"] + params for mod_name in mod_list: mod_name_index = params.index(mod_name) if mod_name.startswith("rqalpha_mod_sys_"): six.print_('System Mod can not be installed or uninstalled') return if "rqalpha_mod_" in mod_name: lib_name = mod_name else: lib_name = "rqalpha_mod_" + mod_name params[mod_name_index] = lib_name # Uninstall Mod uninstalled_result = pip_main(params) # Remove Mod Config from rqalpha.utils.config import user_mod_conf_path, load_yaml user_conf = load_yaml(user_mod_conf_path()) if os.path.exists( user_mod_conf_path()) else { 'mod': {} } for mod_name in mod_list: if "rqalpha_mod_" in mod_name: mod_name = mod_name.replace("rqalpha_mod_", "") del user_conf['mod'][mod_name] dump_config(user_mod_conf_path(), user_conf) return uninstalled_result
def uninstall(params): """ Uninstall third-party Mod """ from pip import main as pip_main from pip.commands.uninstall import UninstallCommand params = [param for param in params] options, mod_list = UninstallCommand().parse_args(params) params = ["uninstall"] + params for mod_name in mod_list: mod_name_index = params.index(mod_name) if mod_name.startswith("rqalpha_mod_sys_"): print('System Mod can not be installed or uninstalled') return if "rqalpha_mod_" in mod_name: lib_name = mod_name else: lib_name = "rqalpha_mod_" + mod_name params[mod_name_index] = lib_name # Uninstall Mod pip_main(params) # Remove Mod Config mod_config_path = get_default_config_path("mod_config") mod_config = load_config(mod_config_path, loader=yaml.RoundTripLoader, verify_version=False) for mod_name in mod_list: if "rqalpha_mod_" in mod_name: mod_name = mod_name.replace("rqalpha_mod_", "") del mod_config['mod'][mod_name] dump_config(mod_config_path, mod_config) list({})
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)
raise Exception('invalid select_date: %s, must be ' '%s or newer.' % (select_date, min_date)) return versions[bisect([x[0] for x in versions], select_date) - 1][1] 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()]
#!/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)
def uninstall(reqs, dont_prompt=False): cmd = UninstallCommand() for req in reqs: _uninstall(req, cmd, dont_prompt)
versions = sorted(versions) min_date = versions[0][0] if select_date < min_date: raise Exception("invalid select_date: %s, must be " "%s or newer." % (select_date, min_date)) return versions[bisect([x[0] for x in versions], select_date) - 1][1] 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()]
#!/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.