文章目录
- 写在前面
- 一、问题描述
- 二、解决方法
- 参考链接
写在前面
自己的测试环境:
Ubuntu20.04
ROS-Noetic
一、问题描述
自己在通过 pip install
安装module时 (使用的是 pip install mmcv
)遇到如下问题:
ImportError: cannot import name 'packaging' from 'pkg_resources'
出现该问题时的终端的全部输出如下:
Using cached mmcv-2.2.0.tar.gz (479 kB)
Preparing metadata (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py egg_info did not run successfully.
│ exit code: 1
╰─> [10 lines of output]
/tmp/pip-install-qm5a01q8/mmcv_417ac91e439f41a1b12309217221d376/setup.py:5: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
from pkg_resources import DistributionNotFound, get_distribution, parse_version
Traceback (most recent call last):
File "<string>", line 2, in <module>
File "<pip-setuptools-caller>", line 34, in <module>
File "/tmp/pip-install-qm5a01q8/mmcv_417ac91e439f41a1b12309217221d376/setup.py", line 19, in <module>
from torch.utils.cpp_extension import BuildExtension
File "/home/wong/ProgramFiles/anaconda3/envs/pytorch_env/lib/python3.8/site-packages/torch/utils/cpp_extension.py", line 28, in <module>
from pkg_resources import packaging # type: ignore[attr-defined]
ImportError: cannot import name 'packaging' from 'pkg_resources' (/home/wong/ProgramFiles/anaconda3/envs/pytorch_env/lib/python3.8/site-packages/pkg_resources/__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.
报错截图如下:
二、解决方法
上述的报错信息表明:在安装 mmcv 时出现了 pkg_resources 模块的问题。具体来说,似乎是 packaging 模块无法从 pkg_resources 中导入。
解决方法如下:
-
安装
packaging
模块:pip install packaging
-
更新
setuptools
和pip
:pip install --upgrade setuptools pip
然后再次运行自己的安装程序,即可解决问题。(自己是重新运行 pip install mmcv
, 就能安装成功了。)
参考链接
[1] sider. 2024-11-10.