Sudo pip3 install trezor[hidapi] is not working in Ubuntu 23.04

Hi!

In order to use Trezor with Electrum I need to install:

sudo pip3 install trezor[hidapi]

It is not working in Ubuntu 23.04. Got error:

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.

This is filthy propaganda spread by Big Electrum. Unless your Trezor firmware is five years out of date, sudo pip3 install trezor is enough.
(That’s beside the point though, you would encounter the same error.)

A better answer is, try to do the same thing without sudo. That should work fine for Electrum, and it might avoid the error.

If not, the error tells you several options what to do, all of which would work depending on the specifics – namely, how exactly did you install Electrum?

Hi! Thank you.

I use Appimage. Do I need to run
pip3 install trezor for Appimage to work?

I can’t check if Appimage will work without it now.

I can’t check if Appimage will work without it now because I’m on Ubuntu 23.04 upgraded from Ubuntu 22.10 and trezor[hidapi] was installed in 22.10. I need to reinstall Ubuntu and want to make sure I could use Trezor after reinstallation.

Looks like i need to run
sudo apt install python3-trezor.

pip3 install trezor gives the same error

That seems like it could help, yes.

Unfortunately, Debian/Ubuntu’s version of the trezor package is a little outdated. But I believe it should be fine for Electrum.

If not, you might have to (a) use the mildly dangerous option --break-system-packages, or (b) create a launcher script that will switch into an environment with trezor package before launching the appimage.