How to use the pip.main function in pip

To help you get started, we’ve selected a few pip examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github cloudviz / agentless-system-crawler / tests / unit / test_app_db2.py View on Github external
import mock
import pip
from unittest import TestCase
from plugins.applications.db2 import db2_crawler
from plugins.applications.db2.feature import DB2Feature
from plugins.applications.db2.db2_container_crawler \
    import DB2ContainerCrawler
from plugins.applications.db2.db2_host_crawler \
    import DB2HostCrawler
from utils.crawler_exceptions import CrawlError
from requests.exceptions import ConnectionError


pip.main(['install', 'ibm_db'])


class MockedDB2Container1(object):

    def __init__(self, container_id):
        ports = "[ {\"containerPort\" : \"50000\"} ]"
        self.inspect = {"State": {"Pid": 1234}, "Config": {"Labels":
                                                           {"annotation.io.kubernetes.container.ports": ports}}}


class MockedDB2Container2(object):

    def __init__(self, container_id):
        self.inspect = {"State": {"Pid": 1234},
                        "Config": {"Labels": {"dummy": "dummy"}}}
github asciimoo / autodep / autodep.py View on Github external
def pip_install(package_name, interactive=True):
    package_name = package_name.split('.')[0]
    if package_name in _package_name_map:
        package_name = _package_name_map[package_name]
    pip_args = ['-q', 'install']
    pip_args.append(package_name)

    if interactive and not yesno('Missing package: "{0}". Do you want to install?'.format(package_name)):
        return -1

    pip_ret = pip.main(pip_args)

    if pip_ret != 0:
        if yesno('Pip cannot install package, maybe package name differs from module name. Try with another name?'):
            return pip_install(raw_input('package name: ').strip(), False)
    else:
        reload(site)

    return pip_ret
github LaserQueue / LaserQueue / scripts / initialize.py View on Github external
if package in installed_packages:
			continue # Don't do anything if the package is installed
		if "netifaces" in installed_packages and not connected_to_internet():
			color_print("No internet connection. Skipping package install.", color=ansi_colors.YELLOW)
			return
		installed = True

		# Ask if they want to install this dependency
		confirm = ("y" if args.all else "")
		while confirm not in ["y", "n"]:
			confirm = color_input("Install dependency {dep}? (y/n) ", dep=package).lower().strip()

		if confirm == "n": # If the person chose not to install the dependency
			color_print("WARNING: Program may not run without this library.", color=ansi_colors.YELLOW)
			continue # Don't do anything
		if pip.main(["install", package]) and os.name != "nt": # If the install fails and this is a *nix system:
			# Ask again, with minor error colors
			confirm = ("y" if args.all else "")
			while confirm not in ["y", "n"]:
				confirm = color_input("Install failed, try again with elevated permissions? (y/n) ", color=ansi_colors.RED).lower().strip()

			if confirm == "n": # If the person chose not to install the dependency
				color_print("WARNING: Program may not run without this library.", color=ansi_colors.YELLOW)
				continue # Don't do anything
			if not os.system("sudo pip3 install "+package): # Try again with root permissions
				installed_packages.append(package) # If it succeeds, add it to the installed packages
		else:
			installed_packages.append(package) # If it succeeds at first, add it to the installed packages
	if installed:
		for package in PACKAGES:
			if package not in installed_packages:
				color_print("Failed to install dependency {dep}.", color=ansi_colors.DARKRED, dep=package)
github errbotio / errbot / tools / py2conv.py View on Github external
def convert_to_python2():
    """
    Convert errbot source code (which is written for Python 3) to
    Python 2-compatible code (in-place) using lib3to2.
    """
    try:
        from lib3to2 import main as three2two
    except ImportError:
        print("Installing Err under Python 2, which requires 3to2 to be installed, but it was not found")
        print("I will now attempt to install it automatically, but this requires at least pip 1.4 to be installed")
        print("If you get the error 'no such option: --no-clean', please `pip install 3to2` manually and "
              "then `pip install err` again.")

        from pip import main as mainpip
        mainpip(['install', '3to2', '--no-clean'])
        from lib3to2 import main as three2two

    files_to_convert = list(walk_lib3to2_input_sources())
    three2two.main("lib3to2.fixes", ["-n", "--no-diffs", "-w"] + files_to_convert)
github IronLanguages / ironpython2 / External.LCA_RESTRICTED / Languages / IronPython / 27 / Lib / ensurepip / __init__.py View on Github external
def _run_pip(args, additional_paths=None):
    # Add our bundled software to the sys.path so we can import it
    if additional_paths is not None:
        sys.path = additional_paths + sys.path

    # Install the bundled software
    import pip
    pip.main(args)
github scragg0x / realms-wiki / realms / commands.py View on Github external
def install_whoosh():
    pip.main(['install', 'Whoosh'])
github lmb-freiburg / freihand / eval.py View on Github external
def install(package):
    if hasattr(pip, 'main'):
        pip.main(['install', package])
    else:
        pip._internal.main(['install', package])
github kromtech / key-inspector / key-inspector.py View on Github external
def install_and_import(pkg):
    """
    Installs latest versions of required packages.
    :param pkg: Package name.
    """
    import importlib
    try:
        importlib.import_module(pkg)
    except ImportError:
        import pip
        pip.main(["install", pkg])
    finally:
        globals()[pkg] = importlib.import_module(pkg)
github serverdensity / sd-agent / utils / flare.py View on Github external
def _pip_freeze(self):
        try:
            import pip
            pip.main(['freeze', '--no-cache-dir'])
        except ImportError:
            print 'Unable to import pip'
github ehennenfent / binja_sensei / __init__.py View on Github external
def handle_dependencies(plugin):
    path = user_plugin_path.replace('plugins', 'repositories/default/plugins')
    plugin_json = '{}/{}/plugin.json'.format(path, plugin.path)
    try:
        with open(plugin_json, 'r') as jsonfile:
            raw_data = json.load(jsonfile)
            dependencies = raw_data["plugin"]["dependencies"]
            if "pip" in dependencies:
                for package in dependencies["pip"]:
                    print("Installing {} dependency: {}".format(plugin.name, package))
                    try:
                        pip.main(['install', '-q', package])
                    except IOError:
                        print("Unable to install {}. Permissions?".format(package))
                        traceback.print_exc()
    except IOError:
        log_error("Unable to install dependencies for {}. Permissions?".format(plugin.name))
        traceback.print_exc()