问题:
ros2 pkg create --build-type ament_python py_pubsub
going to create a new package
package name: py_pubsub
destination directory: /home/zeng/ros2_ws/src
package format: 3
version: 0.0.0
description: TODO: Package description
maintainer: ['zeng <1835023849@qq.com>']
licenses: ['TODO: License declaration']
build type: ament_python
dependencies: []
creating folder ./py_pubsub
creating ./py_pubsub/package.xml
Traceback (most recent call last):
File "/opt/ros/humble/bin/ros2", line 33, in <module>
sys.exit(load_entry_point('ros2cli==0.18.10', 'console_scripts', 'ros2')())
File "/opt/ros/humble/lib/python3.10/site-packages/ros2cli/cli.py", line 91, in main
rc = extension.main(parser=parser, args=args)
File "/opt/ros/humble/lib/python3.10/site-packages/ros2pkg/command/pkg.py", line 37, in main
return extension.main(args=args)
File "/opt/ros/humble/lib/python3.10/site-packages/ros2pkg/verb/create.py", line 184, in main
create_package_environment(package, args.destination_directory)
File "/opt/ros/humble/lib/python3.10/site-packages/ros2pkg/api/create.py", line 99, in create_package_environment
_create_template_file(
File "/opt/ros/humble/lib/python3.10/site-packages/ros2pkg/api/create.py", line 81, in _create_template_file
_expand_template(template_path, template_config, output_file_path)
File "/opt/ros/humble/lib/python3.10/site-packages/ros2pkg/api/create.py", line 31, in _expand_template
em.BUFFERED_OPT: True,
AttributeError: module 'em' has no attribute 'BUFFERED_OPT'
pip show empy
Name: empy
Version: 3.3.4
Summary: A templating system for Python.
Home-page: http://www.alcyone.com/software/empy
Author: Erik Max Francis
Author-email: software@alcyone.com
License: %LICENSE
Location: /home/zeng/anaconda3/lib/python3.8/site-packages
Requires:
Required-by: rocker
从你提供的信息来看,empy 版本是 3.3.4,这通常是与 ROS 2 兼容的版本。然而,问题可能出现在几个方面:
Python 版本冲突:你的 ROS 2 环境可能依赖于 Python 3.10(因为错误信息中提到了 Python 3.10),但你的 Anaconda 环境似乎配置为 Python 3.8(因为 empy 安装在 /home/zeng/anaconda3/lib/python3.8/site-packages)。这可能导致 ROS 2 在尝试使用 empy 时找不到正确的 Python 解释器。
环境激活问题:你可能没有正确激活你的 ROS 2 环境,而是意外地使用了 Anaconda 环境。ROS 2 通常在安装时设置了自己的环境,你需要确保在使用 ROS 2 命令之前激活了正确的环境。
系统路径问题:有时,系统的 PATH 环境变量可能配置不正确,导致 ROS 2 命令使用了错误的 Python 解释器。
解决办法:把empy3.3.4安装在ROS2的python路径下,我的ROS2依赖于python3.10,因此,不能直接pip install empy3.3.4,容易安装到别的python环境中。故执行以下命令:
python3.10 -m pip install empy==3.3.4 -i https://pypi.tuna.tsinghua.edu.cn/simple