[root@python01 psutil-5.7.3]# python3
Python 3.7.9 (default, Sep 8 2020, 13:45:46)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import psutil
Traceback (most recent call last):
File "" , line 1, in <module>
File "/usr/local/src/psutil-5.7.3/psutil/__init__.py", line 99, in <module>
from . import _pslinux as _psplatform
File "/usr/local/src/psutil-5.7.3/psutil/_pslinux.py", line 26, in <module>
from . import _psutil_linux as cext
ImportError: cannot import name '_psutil_linux' from 'psutil' (/usr/local/src/psutil-5.7.3/psutil/__init__.py)
原因可能是,我是源码安装的psutil模块,编译完成后,我是在当前目录中导入psutil,python会从当前目录开始查找模块文件,这样就与源码文件同名混在一起导致导入失败。切换路径就成功了。
[root@python01 src]# ls
psutil-5.7.3 psutil-5.7.3.tar.gz Python-3.7.9 Python-3.7.9.tgz
[root@python01 src]# cd
[root@python01 ~]# python3
Python 3.7.9 (default, Sep 8 2020, 13:45:46)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import psutil
>>>