如何修复 rosdep ERROR: Rosdep experienced an error: 'list' object has no attribute 'encode'
问题
运行 rosdep update 时出现以下错误:
rosdep_output.txt
reading in sources list data from /opt/openrobots/etc/ros/rosdep/sources.list.d
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/osx-homebrew.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/base.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/python.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/rosdep/ruby.yaml
Hit https://raw.githubusercontent.com/ros/rosdistro/master/releases/fuerte.yaml
Query rosdistro index https://raw.githubusercontent.com/ros/rosdistro/master/index-v4.yaml
Add distro "ardent"
ERROR: Rosdep experienced an error: 'list' object has no attribute 'encode'
Please go to the rosdep page [1] and file a bug report with the stack trace below.
[1] : http://www.ros.org/wiki/rosdep
rosdep version: 0.10.30
Traceback (most recent call last):
File "/opt/openrobots/lib/python3.12/site-packages/rosdep2/main.py", line 126, in rosdep_main
exit_code = _rosdep_main(args)
^^^^^^^^^^^^^^^^^^
File "/opt/openrobots/lib/python3.12/site-packages/rosdep2/main.py", line 286, in _rosdep_main
return _no_args_handler(command, parser, options, args)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/openrobots/lib/python3.12/site-packages/rosdep2/main.py", line 294, in _no_args_handler
return command_handlers[command](options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/openrobots/lib/python3.12/site-packages/rosdep2/main.py", line 467, in command_update
update_sources_list(success_handler=update_success_handler,
File "/opt/openrobots/lib/python3.12/site-packages/rosdep2/sources_list.py", line 438, in update_sources_list
retval.append((rds, write_cache_file(sources_cache_dir, dist['distribution'], rosdep_data)))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/openrobots/lib/python3.12/site-packages/rosdep2/sources_list.py", line 493, in write_cache_file
key_hash = compute_filename_hash(filename_key)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/openrobots/lib/python3.12/site-packages/rosdep2/sources_list.py", line 479, in compute_filename_hash
sha_hash.update(filename_key.encode())
^^^^^^^^^^^^^^^^^^^
AttributeError: 'list' object has no attribute 'encode'解决方案
此问题出现是因为你使用的是旧版且过时的 rosdep - 可能是因为你从 robotpkg 仓库安装了 rosdep 0.10.30。要修复此问题,你需要将 rosdep 升级到最新版本:
install_rosdep.sh
sudo apt install python3-rosdep之后,检查是否正在使用新版本。如果没有,你可能需要卸载旧版本。
升级 rosdep 后,你可以再次运行 rosdep update,错误应该会解决。
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow