vpip.pip_api

pip command API.

vpip.pip_api.create_ns_from_dict(d)

Create a namespace object from a dict.

Parameters:

d (dict) – Dictionary.

Return type:

argparse.Namespace

vpip.pip_api.execute_pip(cmd, capture=False)

Run pip command.

Parameters:
  • cmd (str) – pip command. It would be prefixed with python -m pip.

  • capture (bool) – Whether to capture output.

vpip.pip_api.freeze(include: Container[str] | None = None, exclude: Container[str] | None = None) List[str]

List installed packages in pip freeze format (my_pkg==1.2.3).

Parameters:
  • include – If defined, only returns specified packages.

  • exclude – If defined, exclude specified packages.

vpip.pip_api.get_compatible_version(version)

Return the compatible version.

Parameters:

version (str) – Version string.

Returns:

The compatible version which could be used as ~={compatible_version}.

Return type:

str

Suppose the version string is x.y.z:

  • If x is zero then return x.y.z.

  • Otherwise return x.y.

vpip.pip_api.install(packages: List[str], install_scripts: str | None = None, upgrade: bool = False, latest: bool = False, deps: bool = True) List[str]

Install packages and return a list of collected package names.

Parameters:
  • packages – A list of package name, which may include the version specifier. It can also be a URL.

  • install_scripts – Install scripts to a different folder. It uses the --install-option="--install-scripts=..." pip option.

  • upgrade – Upgrade package.

  • latest – Whether upgrade to the latest version. Otherwise upgrade to the compatible version. This option has no effect if package includes specifiers.

  • deps – Whether to install dependencies.

vpip.pip_api.install_editable()

Install the current cwd as editable package.

vpip.pip_api.install_requirements(file='requirements.txt')

Install requirements.txt file.

vpip.pip_api.list_(not_required=False, format='json')

List installed packages.

Return type:

list[argparse.Namespace]

vpip.pip_api.show(packages, verbose=False)

Get package information.

Parameters:
  • packages (list[str]) – A list of package name.

  • verbose (bool) – Whether to return verbose info.

Returns:

A list of namespace objects holding the package information.

Return type:

list[Namespace]

This function uses pip show under the hood. Property name is generated by case_conversion.snakecase().

vpip.pip_api.uninstall(packages)

Uninstall packages.

Parameters:

package (list[str]) – Package name.