## 背景
安装mmcv时,提示
Looking in indexes: https://mirrors.aliyun.com/pypi/simple
Collecting mmcv==2.1.0
Using cached https://mirrors.aliyun.com/pypi/packages/a7/19/f97f0fd4d432113a232e75f965335be6b7bb6557ae9faf8051e9a012cadd/mmcv-2.1.0.tar.gz (471 kB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [12 lines of output]
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/tmp/pip-install-7w6579jw/mmcv_e7740665c062471ba050fb1c6a436394/setup.py", line 477, in <module>
ext_modules=get_extensions(),
File "/tmp/pip-install-7w6579jw/mmcv_e7740665c062471ba050fb1c6a436394/setup.py", line 186, in get_extensions
import psutil
File "/usr/lib/python3/dist-packages/psutil/__init__.py", line 100, 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)
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
error: metadata-generation-failed× Encountered error while generating package metadata.
╰─> See above for output.note: This is an issue with the package mentioned above, not pip.
hint: See above for details.
搜索后,说需要重新安装psutil或者升级psutil:pip3 install --upgrade psutil,但又报错
Looking in indexes: https://mirrors.aliyun.com/pypi/simple
Requirement already satisfied: psutil in /usr/lib/python3/dist-packages (5.4.2)
Collecting psutil
Using cached https://mirrors.aliyun.com/pypi/packages/c5/4f/0e22aaa246f96d6ac87fe5ebb9c5a693fbe8877f537a1022527c47ca43c5/psutil-5.9.8-cp36-abi3-manylinux_2_12_x86_64.manylinux2010_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl (288 kB)
Installing collected packages: psutil
Attempting uninstall: psutil
Found existing installation: psutil 5.4.2
ERROR: Cannot uninstall 'psutil'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
大概意思就是这个库是通过distutils,卸载时无法保证卸载干净,然后就干脆报错不让卸载了,真研究起来还是比较麻烦的。
这个时候直接用大招,pip时添加”--ignore-installed“参数
# 直接pip3 install -U psutil --ignore-installed也可以
python3 -m pip install -U psutil --ignore-installed
成功!!!