Python pip.main() Examples

The following are 30 code examples for showing how to use pip.main(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module pip , or try the search function .

Example 1
Project: iguana   Author: iguana-project   File: make.py    License: Creative Commons Attribution Share Alike 4.0 International 7 votes vote down vote up
def execute_target(cls, *unused):
            # check which requirements should be installed
            requirements_file = _CommonTargets.get_requirements_file()

            # install the requirements
            _CommonTargets.activate_virtual_environment()
            # fix for pip versions below 10.0
            try:
                from pip._internal import main as pipmain
            except ImportError:
                from pip import main as pipmain
            code = pipmain(["install", "-r", requirements_file])

            # check for possible errors
            if code != 0:
                _CommonTargets.exit("Failed while installing the requirements! Please check the errors above.", code)

            # reload the installed packages
            importlib.reload(site) 
Example 2
Project: marcotti   Author: soccermetrics   File: dbsetup.py    License: MIT License 6 votes vote down vote up
def main():
    """
    Main function exposed as script command.
    """
    DATA_PATH = pkg_resources.resource_filename('marcotti', 'data/')
    setup_dict = setup_user_input()
    print("#### Installing database driver ####")
    if setup_dict['dialect'] == 'sqlite':
        print('SQLite database is used -- no external driver needed')
    else:
        pip.main(['install', db_modules.get(setup_dict['dialect'])])
    print("#### Creating settings and data loader modules ####")
    env = jinja2.Environment(loader=jinja2.FileSystemLoader(searchpath=DATA_PATH),
                             trim_blocks=True, lstrip_blocks=True)
    template_files = ['local.skel', 'logging.skel', 'loader.skel']
    output_files = ['{config_file}.py'.format(**setup_dict),
                    'logging.json',
                    '{loader_file}.py'.format(**setup_dict)]
    for template_file, output_file in zip(template_files, output_files):
        template = env.get_template(os.path.join('templates', template_file))
        with open(output_file, 'w') as g:
            result = template.render(setup_dict)
            g.write(result)
            print("Configured {}".format(output_file))
    print("#### Setup complete ####") 
Example 3
Project: pulsar   Author: galaxyproject   File: config.py    License: Apache License 2.0 6 votes vote down vote up
def _handle_install(args, dependencies):
    if args.install and dependencies:
        if pip is None:
            raise ImportError("Bootstrapping Pulsar dependencies requires pip library.")

        pip.main(["install"] + dependencies)


# def _install_pulsar_in_virtualenv(venv):
#     if virtualenv is None:
#         raise ImportError("Bootstrapping Pulsar into a virtual environment, requires virtualenv.")
#     if IS_WINDOWS:
#         bin_dir = "Scripts"
#     else:
#         bin_dir = "bin"
#     virtualenv.create_environment(venv)
#     # TODO: Remove --pre on release.
#     subprocess.call([os.path.join(venv, bin_dir, 'pip'), 'install', "--pre", "pulsar-app"]) 
Example 4
Project: binja_sensei   Author: nccgroup   File: __init__.py    License: MIT License 6 votes vote down vote up
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() 
Example 5
Project: get-pip   Author: pypa   File: pre-10.py    License: MIT License 6 votes vote down vote up
def main():
    tmpdir = None
    try:
        # Create a temporary working directory
        tmpdir = tempfile.mkdtemp()

        # Unpack the zipfile into the temporary directory
        pip_zip = os.path.join(tmpdir, "pip.zip")
        with open(pip_zip, "wb") as fp:
            fp.write(b85decode(DATA.replace(b"\n", b"")))

        # Add the zipfile to sys.path so that we can import it
        sys.path.insert(0, pip_zip)

        # Run the bootstrap
        bootstrap(tmpdir=tmpdir)
    finally:
        # Clean up our temporary working directory
        if tmpdir:
            shutil.rmtree(tmpdir, ignore_errors=True) 
Example 6
Project: presto-admin   Author: prestodb   File: bdist_prestoadmin.py    License: Apache License 2.0 6 votes vote down vote up
def package_dependencies(self, build_dir):
        thirdparty_dir = os.path.join(build_dir, 'third-party')

        requirements = self.distribution.install_requires
        for requirement in requirements:
            pip.main(['wheel',
                      '--wheel-dir={0}'.format(thirdparty_dir),
                      '--no-cache',
                      requirement])

        pip.main(['install',
                  '-d',
                  thirdparty_dir,
                  '--no-cache',
                  '--no-use-wheel',
                  'virtualenv=={0}'.format(self.virtualenv_version)]) 
Example 7
Project: hawthorne   Author: indietyp   File: helper.py    License: GNU Lesser General Public License v3.0 6 votes vote down vote up
def update(supervisor):

  os.chdir(BASE_DIR)
  os.environ.setdefault("DJANGO_SETTINGS_MODULE", "panel.settings")

  tracked = repo.active_branch.tracking_branch()
  if repo.git.rev_parse("@") == repo.git.rev_parse(tracked):
    click.secho('Hawthorne is already up-to-date', bold=True, fg='green')
    return

  repo.git.pull()
  pip.main(['install', '-U', '-r', BASE_DIR + '/requirements.txt'])
  call_command('migrate', interactive=False)
  call_command('collectstatic', interactive=False)

  timezones = run(['mysql_tzinfo_to_sql', '/usr/share/zoneinfo'],
                  stdout=PIPE, stderr=PIPE).stdout
  with connection.cursor() as cursor:
    cursor.execute('USE mysql')
    cursor.execute(timezones)

  if supervisor and which('supervisorctl'):
    run(['supervisorctl', 'reread'], stdout=PIPE, stderr=PIPE)
    run(['supervisorctl', 'update'], stdout=PIPE, stderr=PIPE)
    run(['supervisorctl', 'restart', 'hawthorne:*'], stdout=PIPE, stderr=PIPE) 
Example 8
Project: VMAttack   Author: anatolikalysch   File: setup.py    License: MIT License 5 votes vote down vote up
def do(action, dependency):
    return pip.main([action, dependency]) 
Example 9
Project: SARC-Tool   Author: aboood40091   File: main.py    License: GNU General Public License v3.0 5 votes vote down vote up
def printInfo():
    print("Usage:")
    print("  main [option...] file/folder")
    print("\nPacking Options:")
    print(" -o <output>           output file name (Optional)")
    print(" -little (or -l)       output will be in little endian if this is used")
    print(" -compress <level>     Yaz0 (SZS) compress the output with the specified level(0-9) (1 is the default)")
    print("                       0: No compression (Fastest)")
    print("                       9: Best compression (Slowest)")
    print("\nExiting in 5 seconds...")
    time.sleep(5)
    sys.exit(1) 
Example 10
Project: sqliv   Author: the-robot   File: setup.py    License: GNU General Public License v3.0 5 votes vote down vote up
def dependencies(option):
    """install script dependencies with pip"""

    try:
        with open("requirements.txt", "r") as requirements:
            dependencies = requirements.read().splitlines()
    except IOError:
        print "requirements.txt not found, please redownload or do pull request again"
        exit(1)

    for lib in dependencies:
        pip.main([option, lib]) 
Example 11
Project: sqs-s3-logger   Author: ellimilial   File: lambda_function_builder.py    License: Apache License 2.0 5 votes vote down vote up
def install_packages(dest, packages):
    for p in packages:
        pip.main(['install', '-t', dest, p]) 
Example 12
Project: certidude   Author: laurivosandi   File: common.py    License: MIT License 5 votes vote down vote up
def pip(packages):
    click.echo("Running: pip3 install %s" % packages)
    import pip
    pip.main(['install'] + packages.split(" "))
    return True 
Example 13
Project: recruit   Author: Frank-qlu   File: re-vendor.py    License: Apache License 2.0 5 votes vote down vote up
def vendor():
    pip.main(['install', '-t', here, '-r', 'vendor.txt'])
    for dirname in glob.glob('*.egg-info'):
        shutil.rmtree(dirname) 
Example 14
Project: jbox   Author: jpush   File: re-vendor.py    License: MIT License 5 votes vote down vote up
def vendor():
    pip.main(['install', '-t', here, '-r', 'vendor.txt'])
    for dirname in glob.glob('*.egg-info'):
        shutil.rmtree(dirname) 
Example 15
Project: agentless-system-crawler   Author: cloudviz   File: redis_container_crawler.py    License: Apache License 2.0 5 votes vote down vote up
def crawl(self, container_id=None, **kwargs):

        try:
            import redis
        except ImportError:
            import pip
            pip.main(['install', 'redis'])
            import redis

        # only crawl redis container. Otherwise, quit.
        c = dockercontainer.DockerContainer(container_id)
        port = self.get_port(c)

        if not port:
            return

        state = c.inspect['State']
        pid = str(state['Pid'])
        ips = run_as_another_namespace(
            pid, ['net'], utils.misc.get_host_ip4_addresses)

        for each_ip in ips:
            if each_ip != "127.0.0.1":
                ip = each_ip
                break

        client = redis.Redis(host=ip, port=port)

        try:
            metrics = client.info()
            feature_attributes = feature.create_feature(metrics)
            return [(self.feature_key, feature_attributes, self.feature_type)]
        except:
            logger.info("redis does not listen on port:%d", port)
            raise ConnectionError("no listen at %d", port) 
Example 16
Project: agentless-system-crawler   Author: cloudviz   File: redis_host_crawler.py    License: Apache License 2.0 5 votes vote down vote up
def crawl(self, root_dir='/', **kwargs):
        import pip
        pip.main(['install', 'redis'])
        import redis

        try:
            client = redis.Redis(host='localhost', port=self.default_port)
            metrics = client.info()
        except ConnectionError:
            logger.info("redis does not listen on port:%d", self.default_port)
            raise ConnectionError("no listen at %d", self.default_port)

        feature_attributes = feature.create_feature(metrics)

        return [(self.feature_key, feature_attributes, self.feature_type)] 
Example 17
Project: agentless-system-crawler   Author: cloudviz   File: gpu_host_crawler.py    License: Apache License 2.0 5 votes vote down vote up
def _init_nvml(self):
        if self._load_nvidia_lib() == -1:
            return -1

        try:
            global pynvml
            import pip
            pip.main(['install', '--quiet', 'nvidia-ml-py'])
            import pynvml as pynvml
            pynvml.nvmlInit()
            return 0
        except pynvml.NVMLError, err:
            logger.debug('Failed to initialize NVML: ', err)
            return -1 
Example 18
Project: kobo-predict   Author: awemulya   File: re-vendor.py    License: BSD 2-Clause "Simplified" License 5 votes vote down vote up
def vendor():
    pip.main(['install', '-t', here, '-r', 'vendor.txt'])
    for dirname in glob.glob('*.egg-info'):
        shutil.rmtree(dirname) 
Example 19
Project: vnpy_crypto   Author: birforce   File: re-vendor.py    License: MIT License 5 votes vote down vote up
def vendor():
    pip.main(['install', '-t', here, '-r', 'vendor.txt'])
    for dirname in glob.glob('*.egg-info'):
        shutil.rmtree(dirname) 
Example 20
Project: Hunch   Author: flipkart-incubator   File: custom_package_deployer.py    License: Apache License 2.0 5 votes vote down vote up
def install_custom_module(self, custom_package_name, custom_package_version, model_id, model_version, tar_file_content, delete_previous=False):
        lockfile = self.working_dir + '/' + custom_package_name + '.lock'
        pkg_file_path = self.working_dir + '/' + custom_package_name + '-' + custom_package_version + '-' + str(time.time()) + '.tgz'

        if not os.path.exists(lockfile):
            fd = open(lockfile, 'w+')
            fd.close()

        lockfd = self.lock(lockfile)

        if not os.path.exists(pkg_file_path):
            with open(pkg_file_path, 'w') as fout:
                fout.write(tar_file_content)

        pkg_install_path = self.pkg_install_dir+'/'+custom_package_name

        if os.path.exists(pkg_install_path) and delete_previous==True:
            import shutil
            shutil.rmtree(pkg_install_path, ignore_errors=True)
        elif os.path.exists(pkg_install_path) and delete_previous==False:
            self.unlock(lockfd)
            raise ValueError("Already installed. Set delete_previous to true to override")

        self.check_namespace_clashes(pkg_file_path, custom_package_name, custom_package_version)

        if not os.path.exists(pkg_install_path):
            import pip
            pip.main(['install', pkg_file_path, '--upgrade', '--target', pkg_install_path, '--no-deps'])

        self.unlock(lockfd)
        return pkg_install_path 
Example 21
Project: oss-ftp   Author: aliyun   File: re-vendor.py    License: MIT License 5 votes vote down vote up
def vendor():
    pip.main(['install', '-t', here, '-r', 'vendor.txt'])
    for dirname in glob.glob('*.egg-info'):
        shutil.rmtree(dirname) 
Example 22
Project: oss-ftp   Author: aliyun   File: runner.py    License: MIT License 5 votes vote down vote up
def run():
    base = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    ## FIXME: this is kind of crude; if we could create a fake pip
    ## module, then exec into it and update pip.__path__ properly, we
    ## wouldn't have to update sys.path:
    sys.path.insert(0, base)
    import pip
    return pip.main() 
Example 23
Project: oss-ftp   Author: aliyun   File: __init__.py    License: MIT License 5 votes vote down vote up
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) 
Example 24
Project: rtkbase   Author: Stefal   File: provisioner.py    License: GNU Affero General Public License v3.0 5 votes vote down vote up
def install_pip_packages():

    packages = [
        ("pybluez", "bluetooth")
    ]

    for p in packages:
        try:
            imp.find_module(p[1])
        except ImportError:
            print("No module " + p[0] + " found...")
            pip.main(["install", p[0]]) 
Example 25
Project: anpr   Author: italia   File: re-vendor.py    License: Creative Commons Attribution 4.0 International 5 votes vote down vote up
def vendor():
    pip.main(['install', '-t', here, '-r', 'vendor.txt'])
    for dirname in glob.glob('*.egg-info'):
        shutil.rmtree(dirname) 
Example 26
Project: Safejumper-for-Desktop   Author: proxysh   File: re-vendor.py    License: GNU General Public License v2.0 5 votes vote down vote up
def vendor():
    pip.main(['install', '-t', here, '-r', 'vendor.txt'])
    for dirname in glob.glob('*.egg-info'):
        shutil.rmtree(dirname) 
Example 27
Project: pip-custom-platform   Author: asottile   File: uses_pip.py    License: MIT License 5 votes vote down vote up
def main():
    findlinks, download_dest, pkg, pkgname = sys.argv[1:]
    assert not pip_main(['wheel', pkg, '--wheel-dir', findlinks])
    os.environ.pop('PIP_REQ_TRACKER', None)  # not reentrant
    assert not pip_main([
        'download',
        '--dest', download_dest,
        '--find-links', 'file://{}'.format(findlinks),
        '--no-index',
        pkgname,
    ]) 
Example 28
Project: s3-inspector   Author: clario-tech   File: s3inspector.py    License: GNU General Public License v3.0 5 votes vote down vote up
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) 
Example 29
Project: s3-inspector   Author: clario-tech   File: s3inspector.py    License: GNU General Public License v3.0 5 votes vote down vote up
def main():
    if sys.version[0] == "3":
        raw_input = input
    packages = ["boto3", "botocore", "termcolor", "requests"]
    for package in packages:
        install_and_import(package)
    s3, s3_client = get_s3_obj()
    analyze_buckets(s3, s3_client) 
Example 30
Project: pydep   Author: sourcegraph   File: req.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def resolve(self):
        """
        Downloads this requirement from PyPI and returns metadata from its setup.py.
        Returns an error string or None if no error.
        """
        tmp_dir = tempfile.mkdtemp()
        with open(os.devnull, 'w') as devnull:
            try:
                cmd = ['install', '--quiet',
                       '--download',  tmp_dir,
                       '--build',  tmp_dir,
                       '--no-clean', '--no-deps',
                       '--no-binary', ':all:', str(self.req)]
                pip.main(cmd)
            except Exception as e:
                rmtree(tmp_dir)
                return 'error downloading requirement: {}'.format(str(e))

        project_dir = path.join(tmp_dir, self.req.project_name)
        setup_dict, err = setup_py.setup_info_dir(project_dir)
        if err is not None:
            return None, err
        rmtree(tmp_dir)

        self.metadata = setup_dict
        return None