执行colcon build遇SetuptoolsDeprecationWarning问题求助
解决colcon build时setuptools弃用警告的方案
排查环境版本匹配问题
- 先确认colcon实际调用的Python环境中setuptools版本:
- 执行
which python3找到colcon使用的Python路径 - 用该路径检查版本:
/path/to/python3 -m pip show setuptools - 如果显示的不是58.2.0,说明你降级的是其他环境的setuptools,需要对colcon使用的环境重新降级:
/path/to/python3 -m pip install setuptools==58.2.0
- 执行
强制colcon使用指定Python环境
- 通过环境变量指定:
export PYTHON_EXECUTABLE=/path/to/your/python3 export PYTHONPATH=/path/to/your/env/lib/pythonX.Y/site-packages - 或者在build时直接指定:
colcon build --cmake-args -DPYTHON_EXECUTABLE=/path/to/python3
针对自定义ROS包的修改
如果警告来自你维护的ROS包:
- 在
package.xml中添加依赖声明:<exec_depend>setuptools</exec_depend> - 在
setup.py开头添加警告抑制代码:import warnings from setuptools import SetuptoolsDeprecationWarning warnings.filterwarnings("ignore", category=SetuptoolsDeprecationWarning)
更新colcon工具链
旧版colcon可能依赖弃用的setup.py安装方式,执行升级:
pip3 install --upgrade colcon-common-extensions
处理系统级setuptools(针对Ubuntu/Debian)
如果是系统包管理器安装的setuptools,需要降级系统版本:
- 查找对应版本的包:
apt-cache policy python3-setuptools - 安装指定版本:
(注:版本号需根据你的系统版本调整,确保和58.2.0对应)sudo apt install python3-setuptools=58.2.0-1ubuntu1
内容的提问来源于stack exchange,提问作者Mehdi Ghorbani
相关产品推荐
相关产品推荐

