- 创建者: 虚拟的现实,上次更新时间:2月 13, 2025 需要 2 分钟阅读时间
pip (error: externally-managed-environment)
故障描述
故障现象为通过 pip 安装组件时提示 error: externally-managed-environment 错误
环境:debian 12
root@debian:/tmp/llama.cpp-master# pip install --upgrade pip
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.11/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.
解决方案
使用 find 命令查找 EXTERNALLY-MANAGED 文件删除即可
- 先确认 python 组件是否完整
- 设置软件国内镜像并更新
- 找到对应的文件并删除
sed -i 's/snapshot.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list.d/debian.sources sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list.d/debian.sources pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple apt update apt install python3-full find / -name "EXTERNALLY-MANAGED" rm /usr/lib/python3.11/EXTERNALLY-MANAGED
root@debian:/tmp/llama.cpp-master# pip install --upgrade pip
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: pip in /usr/lib/python3/dist-packages (23.0.1)
Collecting pip
Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c9/bc/b7db44f5f39f9d0494071bddae6880eb645970366d0a200022a1a93d57f5/pip-25.0.1-py3-none-any.whl (1.8 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 1.8/1.8 MB 4.0 MB/s eta 0:00:00
Installing collected packages: pip
Attempting uninstall: pip
Found existing installation: pip 23.0.1
Not uninstalling pip at /usr/lib/python3/dist-packages, outside environment /usr
Can't uninstall 'pip'. No files were found to uninstall.
Successfully installed pip-25.0.1
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
No module named 'numpy'
故障描述
通过 llama.cpp 转换模型格式操作过程中,使用“./convert_hf_to_gguf.py /data/models/models/AI-ModelScope/phi-2” 转换时存在错误提示
root@debian:/tmp/llama.cpp-master# ./convert_hf_to_gguf.py /data/models/models/AI-ModelScope/phi-2
Traceback (most recent call last):
File "/tmp/llama.cpp-master/./convert_hf_to_gguf.py", line 21, in <module>
import numpy as np
ModuleNotFoundError: No module named 'numpy'
解决方案
安装对应的组件
pip show numpy pip install numpy
ModuleNotFoundError: No module named 'yaml'
故障描述
通过 llama.cpp 转换模型格式操作过程中,使用“./convert_hf_to_gguf.py /data/models/models/AI-ModelScope/phi-2” 转换时存在错误提示
root@debian:/tmp/llama.cpp-master# ./convert_hf_to_gguf.py /data/models/models/AI-ModelScope/phi-2/
Traceback (most recent call last):
File "/tmp/llama.cpp-master/./convert_hf_to_gguf.py", line 29, in <module>
import gguf
File "/tmp/llama.cpp-master/gguf-py/gguf/__init__.py", line 9, in <module>
from .metadata import *
File "/tmp/llama.cpp-master/gguf-py/gguf/metadata.py", line 5, in <module>
import yaml
ModuleNotFoundError: No module named 'yaml'
解决方案
安装对应的组件
pip show pyyaml pip install pyyaml
- 无标签