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
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
Alternative Solution: System-Wide Installation
In exceptional cases, if system-wide installation is necessary, consider the following options:
Adding to Pip's Configuration:
Add the following lines to ~/.config/pip/pip.conf:
[global] break-system-packages = true
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!