Home > Backend Development > Python Tutorial > How to Avoid the \'error: externally-managed-environment\' When Using pip3?

How to Avoid the \'error: externally-managed-environment\' When Using pip3?

DDD
Release: 2024-12-01 01:26:15
Original
991 people have browsed it

How to Avoid the

Avoid "error: externally-managed-environment" While Using Pip 3

The error "error: externally-managed-environment" arises when attempting to install Python packages system-wide using pip install xyz, indicating an externally managed environment on Linux machines. To resolve this issue, consider the following:

Preferred Solution: Using a Virtual Environment

The best practice for installing Python libraries and applications is to isolate them in a Python virtual environment. This prevents interference with other system components.

  • Using Pipx for Applications:
    For applications, install pipx as a system package:

    apt install pipx
    pipx install some-python-application
    Copy after login
  • Creating a Virtual Environment Yourself:
    Create a virtual environment using venv and install libraries within it:

    python -m venv my-venv
    my-venv/bin/pip install some-python-library
    Copy after login

Alternative Solution: System-Wide Installation

In exceptional cases, if system-wide installation is necessary, consider the following options:

  • Using Pip's --break-system-packages Flag:
    Run pip install xyz with the --break-system-packages flag, but be aware that this may compromise system stability.
  • Adding to Pip's Configuration:
    Add the following lines to ~/.config/pip/pip.conf:

    [global]
    break-system-packages = true
    Copy after login

The above is the detailed content of How to Avoid the \'error: externally-managed-environment\' When Using pip3?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template