On my system (Raspbian Buster, raspberry pi CM4), packages installed with 'pip3 install ' are not available when I run 'sudo python3':
$ pip3 freeze |grep numpy
numpy==1.21.5
$ sudo python3
Python 3.7.3 (default, Jan 22 2021, 20:04:44)
[GCC 8.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import numpy
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'numpy'
There is also a difference in the output of 'pip3 freeze' and 'sudo pip3 freeze':
$ pip3 freeze |grep numpy
numpy==1.21.5
$ sudo pip3 freeze |grep numpy
<no output>
Both run from the same executable ('/usr/bin/pip3' and '/usr/bin/python3') so how come the environments of these 2 users are different?
Is there a way to use 'sudo python3' and still get the packages installed with the user environment?
p.s: I know about virtualenv, but I would prefer not to use it if possible