紧急通知:禁止一切关于政治&VPN翻墙等话题,发现相关帖子会立马删除封号
小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
非oop方法编写一个节点提示找不到rclpy
-
ROS2创建节点日志报错
问题描述:在学习动手学ROS2教程中的3.4章节,使用非oop方法编写一个节点,步骤紧跟教程文档操作,但是还是报错找不到rclpy
具体细节和上下文:
环境使用的是ubuntu18,ROS2 dashing python 3.6 以下图片是整个节点创建完成后的截图(已经执行source):
尝试运行节点:ros2 run village_li li4_node 出现报错找不到模组rclpy,日志如下:(ros2_dashing_env) root@carl:~/town_ws# ros2 run village_li li4_node Failed to load entry point 'launch': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'info': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'list': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'send_goal': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'show': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'list': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'load': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'standalone': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'types': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'unload': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'start': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'status': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'stop': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'get': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'list': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'nodes': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'set': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'info': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'list': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'delete': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'get': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'list': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'set': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'create_key': cannot import name 'etree' from 'lxml' (/usr/lib/python3/dist-packages/lxml/**init**.py) Failed to load entry point 'create_keystore': cannot import name 'etree' from 'lxml' (/usr/lib/python3/dist-packages/lxml/**init**.py) Failed to load entry point 'create_permission': cannot import name 'etree' from 'lxml' (/usr/lib/python3/dist-packages/lxml/**init**.py) Failed to load entry point 'distribute_key': cannot import name 'etree' from 'lxml' (/usr/lib/python3/dist-packages/lxml/**init**.py) Failed to load entry point 'generate_artifacts': cannot import name 'etree' from 'lxml' (/usr/lib/python3/dist-packages/lxml/**init**.py) Failed to load entry point 'generate_policy': cannot import name 'etree' from 'lxml' (/usr/lib/python3/dist-packages/lxml/**init**.py) Failed to load entry point 'list_keys': cannot import name 'etree' from 'lxml' (/usr/lib/python3/dist-packages/lxml/**init**.py) Failed to load entry point 'call': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'list': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'bw': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'delay': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'echo': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'hz': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'info': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'list': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Failed to load entry point 'pub': 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions Traceback (most recent call last): File "/root/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 "/usr/lib/python3/dist-packages/pkg_resources/**init**.py", line 480, in load_entry_point return get_distribution(dist).load_entry_point(group, name) File "/usr/lib/python3/dist-packages/pkg_resources/**init**.py", line 2693, in load_entry_point return ep.load() File "/usr/lib/python3/dist-packages/pkg_resources/**init**.py", line 2324, in load return self.resolve() File "/usr/lib/python3/dist-packages/pkg_resources/**init**.py", line 2330, in resolve module = **import**(self.module_name, fromlist=['**name**'], level=0) File "/root/town_ws/install/village_li/lib/python3.8/site-packages/village_li/li4.py", line 2, 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 "/usr/lib/python3.8/importlib/**init**.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) 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](https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-without-library-present-on-the-system)' for possible solutions
尝试过的解决方法:
排错1:编写脚本查看是否能正常导入rclpy和创建节点,脚本代码如下:import sys import rclpy print(sys.version) print(sys.path) print(rclpy.__file__) try: import rclpy from rclpy.node import Node print("Successfully imported rclpy and Node.") except ImportError as e: print(f"Failed to import rclpy or Node: {e}") def main(args=None): rclpy.init(args=args) try: node = Node("test_node") print("Successfully created Node.") except Exception as e: print(f"Failed to create Node: {e}") finally: rclpy.shutdown() if __name__ == "__main__": main()
执行结果如下:
(ros2_dashing_env) root@carl:~/town_ws# python3 env_test.py 3.6.13 |Anaconda, Inc.| (default, Jun 4 2021, 14:25:59) [GCC 7.5.0] ['/root/town_ws', '/opt/ros/dashing/lib/python3.6/site-packages', '/root/anaconda3/envs/ros2_dashing_env/lib/python36.zip', '/root/anaconda3/envs/ros2_dashing_env/lib/python3.6', '/root/anaconda3/envs/ros2_dashing_env/lib/python3.6/lib-dynload', '/root/anaconda3/envs/ros2_dashing_env/lib/python3.6/site-packages'] /opt/ros/dashing/lib/python3.6/site-packages/rclpy/__init__.py Successfully imported rclpy and Node. Successfully created Node. (ros2_dashing_env) root@carl:~/town_ws#
结果显示能正常导入rclpy and Node并且能创建节点。
排错2:编写脚本查看环境变量,代码如下:
echo "Checking if rclpy is installed..." if pip list | grep -q rclpy; then echo "rclpy is installed." else echo "rclpy is not installed. Please install it using 'pip install rclpy'." fi echo "Checking PYTHONPATH..." echo $PYTHONPATH echo "Testing rclpy import..." python -c "import rclpy; from rclpy.node import Node; print('rclpy imported successfully')" || echo "Failed to import rclpy" echo "Sourcing ROS 2 environment..." source /opt/ros/dashing/setup.bash echo "Checking ROS environment variables..." printenv | grep ROS
执行结果如下:
(ros2_dashing_env) root@carl:~/town_ws# bash check_ros_env.sh Checking if rclpy is installed... ERROR: Pipe to stdout was broken Exception ignored in: <_io.TextIOWrapper name='<stdout>' mode='w' encoding='UTF-8'> BrokenPipeError: [Errno 32] Broken pipe rclpy is installed. Checking PYTHONPATH... /opt/ros/dashing/lib/python3.6/site-packages Testing rclpy import... rclpy imported successfully Sourcing ROS 2 environment... Checking ROS environment variables... ROS_VERSION=2 ROS_PYTHON_VERSION=3 ROS_DISTRO=dashing
本人只会这两种排查方式,排查后仍无法解决问题,请各位大佬指教。
-
@TsharkYang 跟你的虚拟环境有关系,3.8 应该是ubuntu20的默认版本, 3.6 才是ubuntu18 的系统。
你可以参考下这个:
https://fishros.org.cn/forum/topic/554/jupyter新建python3文件终端报错-导入rclpy报错/2
-
@小鱼 你好,我的虚拟环境是python3.6的,并且我在setup.py中指定了编译版本为3.6,但是编译出来的文件还是3.8的