Skip to main content

Pip 正在集成到 Linux repository 中

· 2 min read
Wayne
Wayne

Pip 正在集成到 Linux repository 中

现在 再使用 pip install 可能会 提示以下消息

error: externally-managed-environment

× This environment is externally managed
╰─>
The system-wide python installation should be maintained using the system
package manager (apk) only.

If the package in question is not packaged already (and hence installable via
"apk add py3-somepackage"), please consider installing it inside a virtual
environment, e.g.:

python3 -m venv /path/to/venv
. /path/to/venv/bin/activate
pip install mypackage

To exit the virtual environment, run:

deactivate

The virtual environment is not deleted, and can be re-entered by re-sourcing
the activate file.

To automatically manage virtual environments, consider using pipx (from the
pipx package).

note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages.
hint: See PEP 668 for the detailed specification.

你可能需要 将 pip install somepackage 替换为 apk add py3-somepackage (Alpine Linux).

其实这是一个好消息

  1. python 的包本身就是安装到系统的某个目录中,而不是安装到项目目录中。系统软件包接管 这很合理。
  2. 对于国内这样的糟糕的网络,镜像站则是必须的,对于 pip 来说,可以少设置一层 镜像或代理,而且多亏了这些镜像站,速度非常的快。