为什么不能使用pip3安装的模块

时间:2017-12-11 22:13:15

标签: python python-3.x

我已将操作系统更新到Fedora 27,并且在root用户运行Python时遇到了问题。我无法导入我用pip3安装的模块,比如psutils

我已经通过pip3安装了psutil

[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

我可以通过普通用户

导入psutil
[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
>>> 

但是在运行root时我无法导入psutil。

[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 ~]$ 

似乎在运行普通用户时,'/usr/local/lib64/python3.6/site-packages''/usr/local/lib/python3.6/site-packages'被添加到sys.path,但是如何在运行root时将这些添加到python3?

0 个答案:

没有答案