使用vLLM部署大模型
$ pip install -U "huggingface_hub[cli]"
error: externally-managed-environment
× This environment is externally managed
╰─> To install Python packages system-wide, try apt install
python3-xyz, where xyz is the package you are trying to
install.
If you wish to install a non-Debian-packaged Python package,
create a virtual environment using python3 -m venv path/to/venv.
Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make
sure you have python3-full installed.
If you wish to install a non-Debian packaged Python application,
it may be easiest to use pipx install xyz, which will manage a
virtual environment for you. Make sure you have pipx installed.
See /usr/share/doc/python3.12/README.venv for more information.
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.这个错误是因为你正在使用 Ubuntu 23.04+、Debian 12+ 或其他遵循 PEP 668 标准的现代 Linux 发行版。系统为了保护自身稳定性,禁止直接使用 pip 向系统级 Python 环境中安装第三方包,以防止与系统包管理器(apt)发生冲突。
针对你想安装 huggingface_hub[cli] 的需求,以下是三种推荐解决方案,按推荐程度排序:
推荐使用虚拟环境(最推荐,标准做法):
这是 Python 开发的最佳实践,既能隔离依赖,又不会破坏系统环境。
创建虚拟环境:
python3 -m venv hf-env激活虚拟环境:
source hf-env/bin/activate此时你的终端提示符前会出现 (hf-env),表示已进入隔离环境。
在虚拟环境中安装:
pip install -U "huggingface_hub[cli]"使用 CLI 工具:
只要虚拟环境处于激活状态,你就可以直接使用 hf 或 huggingface-cli 命令。