psutil is a third-party package and needs to be installed separately.
The reason is that instead of using python3.8 that comes with ubuntu20, I installed a python3.9.
The coexistence of python3.8 and 3.9 requires us to resolve conflicts ourselves.
Python 3.9.5 (default, May 19 2021, 11:32:47)
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import psutil
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/python3/dist-packages/psutil/__init__.py", line 95, in <module>
from . import _pslinux as _psplatform
File "/usr/lib/python3/dist-packages/psutil/_pslinux.py", line 26, in <module>
from . import _psutil_linux as cext
ImportError: cannot import name '_psutil_linux' from partially initialized module 'psutil' (most likely due to a circular import) (/usr/lib/python3/dist-packages/psutil/__init__.py)
>>> exit
Solution:
pip install psutil -U
Why use the -U
parameter?
In [1]: import sys
In [2]: sys.path
Out[2]:
['/home/bot/.local/bin',
'/usr/lib/python39.zip',
'/usr/lib/python3.9',
'/usr/lib/python3.9/lib-dynload',
'',
'/home/bot/.local/lib/python3.9/site-packages',
'/usr/local/lib/python3.9/dist-packages',
'/usr/lib/python3/dist-packages',
'/home/bot/.local/lib/python3.9/site-packages/IPython/extensions',
'/home/bot/.ipython']
In [3]: exit
Because the python interpreter will first search for packages in the user directory when looking for packages, we install it in our own interpreter environment to avoid conflicts psutil
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。