Install rust with sudo for python cryptography

I am trying to install cryptography on a Raspberry Pi with sudo pip install cryptography which requires Rust >= 1.5.6. I installed Rust with

curl --proto '=https' --tlsv1.2 -sSf | sh

and tried again, but rustc couldn't be found (presumably because it wasn't install with sudo). I tried to install rust with sudo via:

curl --proto '=https' --tlsv1.2 -sSf >
chmod +x
sudo ./

but then I couldn't run export /root/.cargo/etc. I read the following posts:

but haven't been able to find an answer on how to install rust with sudo in order to install cyptography with sudo pip. Please understand that cryptography must be installed with sudo and there is simply no way around it.

Have you tried if the approach of working through a shell opened with sudo -s (or as suggested in the other thread sudo su) might work?

Sudo is a mess, since it doesn't change the HOME environment variable by default. Most likely all you ended up doing was messing up the permissions in your user directory.

You could install rust in full root shell, but I would suggest the better option is to build a package as a normal user and install that system wide. Best option is to build a package for your Linux distro package manger (whatever format that is). That is the proper way of doing this.

Besides, shouldn't all containers and so on be buildable by a recipe these days (part of that whole "cattle not pets" thing cloud people talk about)?

Yes I did try the sudo -s and well as the sudo su approach. Unfortunately, neither of those worked either.

What failed? The rust installation, or only the pip? Did you try running the pip install from the sudo -s shell, too?

Also, do you need the global pip install or is pip install --user sufficient? (Without any sudo)

TIL, apparently sudo -H …cmd… is also a thing…

Rust seems to install fine, but using the sudo su example after I get out of the root shell after running export /root/.cargo/etc and run sudo rustc -V I get sudo: rustc: command not found

Well, if you installed it for root, it won’t exist for the normal user, too, I guess? (Unless perhaps if you install it for both… i.e. multiple installations) I heard your goal is to install a python package, not to use rust? If you want to use rust with the normal user, then you should install it for the normal user (without sudo).

How do I build rust for a normal user and then install it system wide?

Typically (at least in a setup involving rustup) doesn’t get installed ”system wide“, as far as I’m aware. See also: Does support shared .multirust (or whatever) directory? · Issue #313 · rust-lang/rustup · GitHub

For the record, looking at the docs I don’t think that the installation process / instructions for the cryptography package are really designed for not global, but local installation for a single user. (And honestly, for a raspberry pi, shouldn’t that be sufficient?) I’m not a python user myself; looking at online docs it seems like either the global or the local installation might be default, perhaps depending on your distribution, and switching is done via --user or --system flags.

Have you tried if (no sudo) the command pip install --user cryptography works for you? (After rust is installed, normally i.e. also without using sudo, for the current user.)

I tried reinstalling the Raspberry Pi OS and starting from scratch in a sudo -s shell. Then I tried to install cryptography in that same shell and it worked for me. The steps were:

sudo -s
curl --proto '=https' --tlsv1.2 -sSf | sh
apt-get install libssl-dev
pip install cryptography

Thank you so much for your help!

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.