错误:外部管理的环境,PIP

错误:外部管理的环境,PIP

使用 PIP 安装包时出现此错误,如何修复?

[xyro@arch ~]$ pip install flask
error: externally-managed-environment

× This environment is externally managed
╰─> To install Python packages system-wide, try 'pacman -S
    python-xyz', where xyz is the package you are trying to
    install.
    
    If you wish to install a non-Arch-packaged Python package,
    create a virtual environment using 'python -m venv path/to/venv'.
    Then use path/to/venv/bin/python and path/to/venv/bin/pip.
    
    If you wish to install a non-Arch packaged Python application,
    it may be easiest to use 'pipx install xyz', which will manage a
    virtual environment for you. Make sure you have python-pipx
    installed via pacman.

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.
[xyro@arch ~]$ 

答案1

根据说明,您可以通过创建虚拟环境来安装非 Arch 软件包服务。如果您尝试从文件安装多个软件包,此方法也有效requirements.txt。因此,您需要运行以下命令:

python3 -m venv .venv

这会.venv在本地为您的包创建一个文件夹。

source .venv/bin/activate

这将激活你的 Python 虚拟环境。

现在您可以运行pip install -r requirements.txtpip install <package-name>。这只是在系统中安装软件包的更安全的方法。

相关内容