Install PyTorch for all users on Ubuntu

I want to install PyTorch that can be shared by all users of a Ubuntu workstation. If I followed the command provided by “Start Locally”:

pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu118

, the PyTorch package will be installed to .local/lib/python3.10/site-packages/in my own home directory, which cannot be seen by other users. Is there any way to force the installation directory of PyTorch to be in the Ubuntu system (e.g., /usr/lib/python3/dist-packages' which is in sys.path) so that other users of the Ubuntu system could use PyTorch I installed?

My system:

  • Python version: 3.10.12
  • pip version: 22.0.2
  • Ubuntu version 22.04.5 LTS

The install location of Python packages depends on how your Python environment was configured and where the Python interpreter is located. E.g. you could install Python in a “global” folder (e.g. /opt) which would then be accessible for all users.

Is it possible that pytorch has some special code that directs pip3 to forcibly install pytorch package to site.USER_SITE (as if I use --user option but I didn’t)?

The reason is that I forgot to add sudo -H before the given command, so pip falls back to site.USER_SITE because I don’t have permission to write system directory. Now I add “sudo -H” and pytorch is installed to /usr/local/lib/python3.10/dist-packages as desired.

Thanks for reading and replying my question.