ubuntu 18.04 ROS2 dashing 跟着教程学习“编写python 话题发布者”编写完后,ros2 run village_li li4_node没反应
-
按 ctrl+c后,出现错误"Traceback (most recent call last):
File "/home/dell/ROS2/town_ws/install/village_li/lib/village_li/li4_node", line 11, in <module>
load_entry_point('village-li==0.0.0', 'console_scripts', 'li4_node')()
File "/home/dell/ROS2/town_ws/install/village_li/lib/python3.6/site-packages/village_li/li4.py", line 28, in main
rclpy.spin(li4_node)
File "/opt/ros/dashing/lib/python3.6/site-packages/rclpy/init.py", line 189, in spin
executor.spin_once()
File "/opt/ros/dashing/lib/python3.6/site-packages/rclpy/executors.py", line 663, in spin_once
handler, entity, node = self.wait_for_ready_callbacks(timeout_sec=timeout_sec)
File "/opt/ros/dashing/lib/python3.6/site-packages/rclpy/executors.py", line 649, in wait_for_ready_callbacks
return next(self._cb_iter)
File "/opt/ros/dashing/lib/python3.6/site-packages/rclpy/executors.py", line 549, in _wait_for_ready_callbacks
_rclpy.rclpy_wait(wait_set, timeout_nsec)
KeyboardInterrupt"在vscode 中debug li4.py 出现错误“Exception has occurred: ModuleNotFoundError
No module named 'rclpy._rclpy'
The C extension '/opt/ros/dashing/lib/python3.6/site-packages/rclpy/_rclpy.cpython-38-x86_64-linux-gnu.so' isn't present on the system. Please refer to 'https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system' for possible solutions
File "/home/dell/ROS2/town_ws/src/village_li/village_li/li4.py", line 3, in <module>
from rclpy.node import Node”li4.py 的代码是
#!/usr/bin/python3
import rclpy
from rclpy.node import Node
from std_msgs.msg import Stringclass writerNode(Node):
def init(self,name):
super().init(name)
self.get_logger().info("大家好,我是%s." %name)
#2声明并创建发布者
self.pub_novel = self.create_publisher(String,"sexy_girl",10)
self.count=0
self.timer_period =5
self.timer = self.create_timer(self.timer_period, self.timer_callback)def timer_callback(self): msg=String() msg.data="第%d回。第%d次偶遇" % (self.count, self.count) self.pub_novel.publish(msg) #让发布者发布消息 self.get_logger().info("发布了一个小说,内容是:%s"% msg.data) self.count+=1
def main(args=None):
rclpy.init(args=args)
li4_node=writerNode("li4")
rclpy.spin(li4_node)
rclpy.shutdown()麻烦大佬们帮忙解决一下,找了好几天的解决办法了,都没用,说是conda的问题,我deactivate之后,还是不行,有说是python的问题,我都试了,还是不行。
-
@1094971428 在 ubuntu 18.04 ROS2 dashing 跟着教程学习“编写python 话题发布者”编写完后,ros2 run village_li li4_node没反应 中说:
/opt/ros/dashing/lib/python3.6/site-packages
ros版本太老了吧,换成ubuntu22.04 humble吧
-
@1094971428 在 ubuntu 18.04 ROS2 dashing 跟着教程学习“编写python 话题发布者”编写完后,ros2 run village_li li4_node没反应 中说:
Exception has occurred: ModuleNotFoundError
https://fishros.com/d2lros2/#/humble/chapt2/basic/5.Python依赖查找流程
看下这个
-
@小鱼 我按照步骤走了,现在出现 No module named 'rclpy'这个错误,然后我添加库到路径里,结果添加不进去,你有什么解决办法吗?
-
@1094971428 建议跟着新版教程看看:https://fishros.com/d2lros2/
-
您提供的链接是一份ROS2的学习资料,适用于想要学习ROS2的人群。ROS2是ROS的下一代版本,相较于ROS1具有更好的实时性、安全性和可扩展性等优点。学习ROS2可以让您更好地掌握机器人开发的技能和知识,提高机器人开发的效率和质量。该教程涵盖ROS2的基础知识、通信机制、消息传递、参数服务器、行为和服务等方面的内容,对于初学者来说是一个很好的学习资源。
以上为生成回答,仅供参考~
-
@小鱼 我跟着新版教程试了。用export把rclpy的包添加到路径,出现这个错误,ModuleNotFoundError: No module named 'rclpy._rclpy',我找到这个错误包的路径,
ls -l /opt/ros/dashing/lib/python3.6/site-packages/rclpy | grep ._rclpy
-rw-r--r-- 1 root root 40896 5月 22 2021 _rclpy_action.cpython-36m-x86_64-linux-gnu.so
-rw-r--r-- 1 root root 87904 5月 22 2021 _rclpy.cpython-36m-x86_64-linux-gnu.so添加到环境 export PYTHONPATH=/opt/ros/dashing/lib/python3.6/site-packages/rclpy
运行后,又出现python3 second_ros2_node.py
Traceback (most recent call last):
File "second_ros2_node.py", line 3, in <module>
import rclpy
ModuleNotFoundError: No module named 'rclpy'
这个错误,不知道又哪里错了 -
@1094971428 你加错了,是加到上一级目录/opt/ros/dashing/lib/python3.6/site-packages
-
@小鱼 我添加到上一级目录,不出现“No module named 'rclpy',这个错误,但会出现Traceback (most recent call last):
File "/home/dell/ROS2/town_ws/src/village_li/village_li/second_ros2_node.py", line 4, in <module>
from rclpy.node import Node
File "/opt/ros/dashing/lib/python3.6/site-packages/rclpy/node.py", line 39, in <module>
from rclpy.client import Client
File "/opt/ros/dashing/lib/python3.6/site-packages/rclpy/client.py", line 22, in <module>
from rclpy.impl.implementation_singleton import rclpy_implementation as _rclpy
File "/opt/ros/dashing/lib/python3.6/site-packages/rclpy/impl/implementation_singleton.py", line 31, in <module>
rclpy_implementation = _import('._rclpy')
File "/opt/ros/dashing/lib/python3.6/site-packages/rclpy/impl/init.py", line 22, in _import
return importlib.import_module(name, package='rclpy')
File "/home/dell/anaconda3/lib/python3.9/importlib/init.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
ModuleNotFoundError: No module named 'rclpy._rclpy'
这个错误。echo $PYTHONPATH
/opt/ros/dashing/lib/python3.6/site-packages -
@1094971428 在 ubuntu 18.04 ROS2 dashing 跟着教程学习“编写python 话题发布者”编写完后,ros2 run village_li li4_node没反应 中说:
/opt/ros/dashing/lib/python3.6/site-packages
ros版本太老了吧,换成ubuntu22.04 humble吧
-
@小鱼好的,谢谢小鱼
-