MCPcopy Create free account
hub / github.com/modelscope/ms-agent / install_package

Function install_package

ms_agent/utils/utils.py:633–659  ·  view source on GitHub ↗

Check and install a package using pip. Note: The `package_name` may not be the same as the `import_name`. Args: package_name (str): The name of the package to install (for pip install). import_name (str, optional): The name used to import the package.

(package_name: str,
                    import_name: Optional[str] = None,
                    extend_module: str = None)

Source from the content-addressed store, hash-verified

631
632
633def install_package(package_name: str,
634 import_name: Optional[str] = None,
635 extend_module: str = None):
636 """
637 Check and install a package using pip.
638
639 Note: The `package_name` may not be the same as the `import_name`.
640
641 Args:
642 package_name (str): The name of the package to install (for pip install).
643 import_name (str, optional): The name used to import the package.
644 If None, uses package_name. Defaults to None.
645 extend_module (str, optional): The module to extend, e.g. `pip install modelscope[nlp]` when set to 'nlp'.
646 """
647 # Use package_name as import_name if not provided
648 if import_name is None:
649 import_name = package_name
650
651 if extend_module:
652 package_name = f'{package_name}[{extend_module}]'
653
654 if not is_package_installed(import_name):
655 subprocess.check_call(
656 [sys.executable, '-m', 'pip', 'install', package_name])
657 logger.info(f'Package {package_name} installed successfully.')
658 else:
659 logger.info(f'Package {import_name} is already installed.')
660
661
662def extract_by_tag(text: str, tag: str) -> str:

Callers 9

__init__Method · 0.90
__init__Method · 0.90
__init__Method · 0.90
startMethod · 0.90
_check_dependenciesMethod · 0.90
_initMethod · 0.90
markdown_to_htmlMethod · 0.90
markdown_to_docxMethod · 0.90
markdown_to_pptxMethod · 0.90

Calls 1

is_package_installedFunction · 0.85

Tested by

no test coverage detected