$ 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
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.TL;DR: Use
apt install python3-cryptography
instead ofsudo pip install cryptography
.Long story: Mixing two package managers (
apt
andpip
here) is always a bad idea, so error message or not, please avoidsudo 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:
apt install python3-cryptography
instead. In this case there’s no weird mixing of package managers: you installedpython3
usingapt
, you’re installingcryptography
usingapt
: no surprises.python3 -m venv .venv
thensource .venv/bin/activate
, thenpip 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.apt install python3-...
, it would bring the wrong version of the lib. So I use either a venv either apip install cryptography
,pip
will install it in~/.local/lib/
, again no clash betweenapt
andpip
, no surprises.Try that it will be work am sure :
or that
i hope helps u.