小鱼 ROS 2 新书上线!点击链接查看, 新书配套视频点击链接查看。
提问前必看的发帖注意事项—— 提问前必看!不符合要求的问题拒绝回答!!
社区使用指南—如何添加标签修改密码
使用vscode编写第一个节点报错(python实例)
-
设备:jetson nano
架构:arm64
Ubuntu版本:20.04
ros2版本: ros2 foxy
实例代码:
import rclpy
from rclpy.node import Nodedef main():
rclpy.init()
node = Node('pythono_node')
rclpy.spin(node)
rclpy.shutdown()if name=='main':
main()
终端编写方式:(base) bd215@ubuntu:~/chapt2$ python3 ros2_node.py
终端报错:
Traceback (most recent call last):
File "/home/bd215/chapt2/ros2_node.py", line 2, in <module>
from rclpy.node import Node
File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/node.py", line 42, in <module>
from rclpy.client import Client
File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/client.py", line 22, in <module>
from rclpy.impl.implementation_singleton import rclpy_implementation as _rclpy
File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/impl/implementation_singleton.py", line 31, in <module>
rclpy_implementation = _import('._rclpy')
^^^^^^^^^^^^^^^^^^
File "/opt/ros/foxy/lib/python3.8/site-packages/rclpy/impl/init.py", line 28, in _import
return importlib.import_module(name, package='rclpy')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/bd215/mambaforge/lib/python3.12/importlib/init.py", line 90, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'rclpy._rclpy'
The C extension '/opt/ros/foxy/lib/python3.8/site-packages/rclpy/_rclpy.cpython-312-aarch64-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 -
-
@小鱼 我通过更改python优先级后将python的版本改为3.8后解决了问题
sudo update-alternatives --install /home/bd215/mambaforge/bin/python python /home/bd215/mambaforge/bin/python3.12 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python2.7 2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.8 3
sudo update-alternatives --config python
我更改优先级后,可以顺利运行节点程序,再次打开终端,base前缀就消失了
终端运行所以conda指令均报错,
bd215@ubuntu:~$ conda -V
bash: /home/bd215/mambaforge/bin/conda: /home/bd215/mambaforge/bin/python: bad interpreter: No such file or directory
大佬这个怎么解决 -
此回复已被删除!