pip: error: externally-managed-environment
TL;DRThis error appears when you try to install a Python package with pip but the system blocks it to protect important files. Modern operating systems manage Python themselves and do not want outside tools changing those files.
Likely causes
- Trying to install packages directly into the protected system Python instead of a private project foldermost likely
- Running pip on a Linux distribution or macOS setup that enforces external management of Pythonpossible
How to fix it
Safest first: SafeChanges settingsDangerous
Create a virtual environment for your projectChanges settings
This keeps packages separate from the system Python so the error does not appear.
python -m venv myprojectActivate the virtual environmentChanges settings
You must activate it before installing packages inside it.
source myproject/bin/activateInstall the package inside the virtual environmentChanges settings
Run pip install as usual once the environment is active.
pip install <package-name>
If that didn't fix it
You will continue to receive the same error and will not be able to install new Python packages without changing how you run pip.
When to see a technician
If you are working on a company or shared computer and are unsure which Python is safe to modify, ask your system administrator or a developer for help.
Related errors
codeSyntaxError: Cannot use import statement outside a modulecodeTypeError: Cannot read properties of undefined (reading 'map')codedocker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?codePermission denied (publickey). fatal: Could not read from remote repository.codegit push: error: failed to push some refs (rejected, non-fast-forward)