Let's say I've installed torch
using pip3
in my user1
's account.
user1@desktop:~$ pip3 show torch
Name: torch
Version: 1.11.0
Summary: Tensors and Dynamic neural networks in Python with strong GPU acceleration
Home-page: https://pytorch.org/
Author: PyTorch Team
Author-email: packages@pytorch.org
License: BSD-3
Location: /home/user1/.local/lib/python3.8/site-packages
Requires: typing-extensions
Required-by: ogb, pytorch-lightning, torchaudio, torchmetrics, torchvision
As can be seen above, pip3
-installed packages' location is /home/user1/.local/lib/python3.8/site-packages
.
Now, say that I want to run some python file using sudo
privilege. (Assume that I can pass along the correct password when using sudo
privilege.) In this case, however, it returns ModuleNotFoundError
since torch
is installed in my user1
's account, not in root user's.
user1@desktop:~$ sudo python3 toy_example.py
Traceback (most recent call last):
File "toy_example.py", line 1, in <module>
import torch
ModuleNotFoundError: No module named 'torch'
When I attempt to run certain file with sudo
privilege, how can I link python packages installed in ordinary user's account? (e.g., torch
, which is installed in /home/user1/.local/lib/python3.8/site-packages
in the above example) I think it would be possible if I fix some environment variables, but couldn't figure it out.