skip to Main Content
$ sudo pip install cryptography 
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.

Same issue in pip install pynput
How can ı fix this?

3

Answers


  1. This is a result of PEP 668. If you cannot or don’t want to use the venv module, you can force pip to install the package with the --break-system-packages switch, which will override the default behavior.

    Login or Signup to reply.
  2. TL;DR: Use apt install python3-cryptography instead of sudo pip install cryptography.

    Long story: Mixing two package managers (apt and pip here) is always a bad idea, so error message or not, please avoid sudo pip install.

    PEP 668 is a way for distributions to explicitly tell users to avoid falling is this pit. Your distribution used it to tell you to use apt instead.

    In fact there’s three good solutions:

    • Use apt install python3-cryptography instead. In this case there’s no weird mixing of package managers: you installed python3 using apt, you’re installing cryptography using apt: no surprises.
    • Use a venv: python3 -m venv .venv then source .venv/bin/activate, then pip install cryptography. In this case the installation is contained inside the .venv directory: no mixing of what apt does and what pip does, no surprises.
    • Use a Python not provided by your distrib. I often compile many Python interpreters myself using a short bash function, those interpreters are of a different version that the system Python3 so I obviously can’t use apt install python3-..., it would bring the wrong version of the lib. So I use either a venv either a pip install cryptography, pip will install it in ~/.local/lib/, again no clash between apt and pip, no surprises.
    Login or Signup to reply.
  3. Try that it will be work am sure :

    sudo pip3 install cryptography –break-system-packages

    or that

    sudo pip install cryptography –break-system-packages

    i hope helps u.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search