I have updated my operating system to Fedora 27, and I experienced a problem when running Python by root. I cannot import modules I installed with pip3, like psutils
I have installed psutil by pip3
[user@localhost ~]$ sudo pip3 install psutil
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3 install --user` instead.
Requirement already satisfied: psutil in /usr/local/lib64/python3.6/site-packages
I can import psutil by a normal user
[user@localhost ~]$ python3
Python 3.6.3 (default, Oct 9 2017, 12:07:10)
[GCC 7.2.1 20170915 (Red Hat 7.2.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.path)
['', '/usr/lib64/python36.zip', '/usr/lib64/python3.6', '/usr/lib64/python3.6/lib-dynload', '/usr/local/lib64/python3.6/site-packages', '/usr/local/lib/python3.6/site-packages', '/usr/lib64/python3.6/site-packages', '/usr/lib/python3.6/site-packages', '/usr/lib/python3.6/site-packages/pykakasi-0.24-py3.6.egg']
>>> import psutil
>>>
But I cannot import psutil when running root.
[user@localhost ~]$ sudo python3
Python 3.6.3 (default, Oct 9 2017, 12:07:10)
[GCC 7.2.1 20170915 (Red Hat 7.2.1-2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> print(sys.path)
['', '/usr/lib64/python36.zip', '/usr/lib64/python3.6', '/usr/lib64/python3.6/lib-dynload', '/usr/lib64/python3.6/site-packages', '/usr/lib/python3.6/site-packages', '/usr/lib/python3.6/site-packages/pykakasi-0.24-py3.6.egg']
>>> import psutil
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'psutil'
>>>
[user@localhost ~]$
It seems that when running a normal user, '/usr/local/lib64/python3.6/site-packages'
and '/usr/local/lib/python3.6/site-packages'
are added to sys.path
, but how can I add these to python3 when running with root?