ensurepip
pip
软件打包和分发
Added in version 3.4.
源代码: Lib/ensurepip
The ensurepip package provides support for bootstrapping the pip installer into an existing Python installation or virtual environment. This bootstrapping approach reflects the fact that pip is an independent project with its own release cycle, and the latest available stable version is bundled with maintenance and feature releases of the CPython reference interpreter.
In most cases, end users of Python shouldn’t need to invoke this module directly (as pip should be bootstrapped by default), but it may be needed if installing pip was skipped when installing Python (or when creating a virtual environment) or after explicitly uninstalling pip .
注意
This module does not access the internet. All of the components needed to bootstrap pip are included as internal parts of the package.
另请参阅
The end user guide for installing Python packages
The original rationale and specification for this module.
可用性 :非 Emscripten,非 WASI。
本模块不工作 (或不可用) 于 WebAssembly 平台 wasm32-emscripten and wasm32-wasi 。见 WebAssembly 平台 了解更多信息。
wasm32-emscripten
wasm32-wasi
The command line interface is invoked using the interpreter’s -m switch.
-m
The simplest possible invocation is:
python -m ensurepip
This invocation will install pip if it is not already installed, but otherwise does nothing. To ensure the installed version of pip is at least as recent as the one available in ensurepip , pass the --upgrade 选项:
--upgrade
python -m ensurepip --upgrade
默认情况下, pip is installed into the current virtual environment (if one is active) or into the system site packages (if there is no active virtual environment). The installation location can be controlled through two additional command line options:
--root dir : Installs pip relative to the given root directory rather than the root of the currently active virtual environment (if any) or the default root for the current Python installation.
--root dir
--user : Installs pip into the user site packages directory rather than globally for the current Python installation (this option is not permitted inside an active virtual environment).
--user
By default, the scripts pipX and pipX.Y will be installed (where X.Y stands for the version of Python used to invoke ensurepip ). The scripts installed can be controlled through two additional command line options:
pipX
pipX.Y
--altinstall : if an alternate installation is requested, the pipX script will not be installed.
--altinstall
--default-pip : if a “default pip” installation is requested, the pip script will be installed in addition to the two regular scripts.
--default-pip
Providing both of the script selection options will trigger an exception.
ensurepip exposes two functions for programmatic use:
Returns a string specifying the available version of pip that will be installed when bootstrapping an environment.
Bootstraps pip into the current or designated environment.
root specifies an alternative root directory to install relative to. If root is None , then installation uses the default install location for the current environment.
None
upgrade indicates whether or not to upgrade an existing installation of an earlier version of pip to the available version.
user indicates whether to use the user scheme rather than installing globally.
By default, the scripts pipX and pipX.Y will be installed (where X.Y stands for the current version of Python).
若 altinstall is set, then pipX will not be installed.
若 default_pip is set, then pip will be installed in addition to the two regular scripts.
Setting both altinstall and default_pip will trigger ValueError .
ValueError
verbosity controls the level of output to sys.stdout from the bootstrapping operation.
sys.stdout
引发 审计事件 ensurepip.bootstrap 采用自变量 root .
ensurepip.bootstrap
root
The bootstrapping process has side effects on both sys.path and os.environ . Invoking the command line interface in a subprocess instead allows these side effects to be avoided.
sys.path
os.environ
The bootstrapping process may install additional modules required by pip , but other software should not assume those dependencies will always be present by default (as the dependencies may be removed in a future version of pip ).
venv — 虚拟环境的创建
venv
键入搜索术语或模块、类、函数名称。