Sudo non utilizza lo stesso PATH come utente attuale per motivi di sicurezza. In /etc/sudoers c'è un'opzione secure_path che specifica il percorso utilizzato durante l'esecuzione dei comandi con sudo. Il mio ha questo aspetto:
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
Dalla manpage sudo:
secure_path Path used for every command run from sudo. If you don't trust the people running sudo to have a sane PATH environment variable you may want to use this. Another use is if you want to have the “root path” be separate from the “user path”. Users in the group specified by the exempt_group option are not affected by secure_path. This option is not set by default.
Il pip3 probabilmente il comando non si trova nel percorso definito da sudoers file. Puoi aggiungere il percorso a secure_path o fornire il percorso completo al pip3 comando come questo:
sudo /path/to/pip3 install django