我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用pip.main()。
def _install_packages(self, path, packages): """Install all packages listed to the target directory. Ignores any package that includes Python itself and python-lambda as well since its only needed for deploying and not running the code :param str path: Path to copy installed pip packages to. :param list packages: A list of packages to be installed via pip. """ def _filter_blacklist(package): blacklist = ["-i", "#", "Python==", "ardy=="] return all(package.startswith(entry.encode()) is False for entry in blacklist) filtered_packages = filter(_filter_blacklist, packages) # print([package for package in filtered_packages]) for package in filtered_packages: if package.startswith(b'-e '): package = package.replace('-e ', '') logger.info('Installing {package}'.format(package=package)) pip.main(['install', package, '-t', path, '--ignore-installed', '-q'])
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)
def example_instance(tmpdir_factory): from cookiecutter.main import cookiecutter import pip tmpdir = tmpdir_factory.mktemp('example_instance') with tmpdir.as_cwd(): cookiecutter(PROJECT_ROOT, no_input=True, config_file=os.path.join(HERE, 'testconfig.yaml')) instance_path = tmpdir.join('jupyter-widget-testwidgets') with instance_path.as_cwd(): print(str(instance_path)) try: pip.main(['install', '-v', '-e', '.[test]']) yield instance_path finally: try: pip.main(['uninstall', 'ipywidgettestwidgets', '-y']) except Exception: pass
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(base64.decodestring(ZIPFILE)) # Add the zipfile to sys.path so that we can import it sys.path = [pip_zip] + sys.path # Run the bootstrap bootstrap(tmpdir=tmpdir) finally: # Clean up our temporary working directory if tmpdir: shutil.rmtree(tmpdir, ignore_errors=True)
def _pip_main(self, *args): """Run pip.main with the specified ``args`` """ if self.quiet: import logging pip_log = logging.getLogger("pip") _level = pip_log.level pip_log.setLevel(logging.CRITICAL) elif self._should_color(): self._sys.stdout.write("\x1b[36m") try: self._pip.main(list(args)) finally: if self.quiet: pip_log.setLevel(_level) elif self._should_color(): self._sys.stdout.write("\x1b[0m") self._sys.stdout.flush()
def run(self): # Install all requirements failed = [] for req in requirements: if pip.main(["install", req]) == 1: failed.append(req) if len(failed) > 0: print("") print("Error installing the following packages:") print(str(failed)) print("Please install them manually") print("") raise OSError("Aborting") # install MlBox install.run(self)
def pip_command_output(pip_args): """ Get output (as a string) from pip command :param pip_args: list o pip switches to pass :return: string with results """ import sys import pip from io import StringIO # as pip will write to stdout we use some nasty hacks # to substitute system stdout with our own old_stdout = sys.stdout sys.stdout = mystdout = StringIO() pip.main(pip_args) output = mystdout.getvalue() mystdout.truncate(0) sys.stdout = old_stdout return output
def main(): if os.name != "nt": if os.getuid() == 0: os.system("git clone https://github.com/joshDelta/smsBomber.git /usr/share/smsBomber") for i in ["termcolor", "datetime"]: pip.main(["install", i]) file = open("/usr/bin/smsBomber", "w") file.write(content) file.close() os.system("chmod +x /usr/bin/smsBomber") print "\n\n[+] Installation finished, type 'python smsbomber.py ' to use program!" else: print "Run as root!" else: print "This script doesn't work on Windows!"
def main(): print("FiringMain") parser = argparse.ArgumentParser() parser.add_argument('--save_dir', type=str, default='models/reddit', help='model directory to store checkpointed models') parser.add_argument('-n', type=int, default=500, help='number of characters to sample') parser.add_argument('--prime', type=str, default=' ', help='prime text') parser.add_argument('--beam_width', type=int, default=2, help='Width of the beam for beam search, default 2') parser.add_argument('--temperature', type=float, default=1.0, help='sampling temperature' '(lower is more conservative, default is 1.0, which is neutral)') parser.add_argument('--relevance', type=float, default=-1., help='amount of "relevance masking/MMI (disabled by default):"' 'higher is more pressure, 0.4 is probably as high as it can go without' 'noticeably degrading coherence;' 'set to <0 to disable relevance masking') args = parser.parse_args() sample_main(args)
def list_dependencies(args): """Prints a list of dependencies :param args: command line args :return: None """ ignore_list = args.ignore dependencies_main = args.main dependencies_secondary = args.secondary tree = get_package_tree(ignore_list=ignore_list) filtered_tree = {} if not dependencies_main and not dependencies_secondary: filtered_tree = get_all_packages(tree) elif dependencies_main: filtered_tree = get_main_packages(tree) elif dependencies_secondary: filtered_tree = get_secondary_packages(tree) package_list = get_package_list(filtered_tree) printer.package_list(package_list)
def install_packages(_package_names): """ Install the packages listed if not present :param _package_names: A list of the packages :return: """ _installed = [] for _curr_package in _package_names: if importlib.util.find_spec(_curr_package) is None: print(_curr_package + " not installed, installing...") pip.main(['install', _curr_package]) print(_curr_package + " installed...") _installed.append(_curr_package) else: print(_curr_package + " already installed, skipping...") return _installed