Import rclpy in a capsuled python environment
Hey there!
I want to use Ros / Ros2 with Blender, which provides an extensive python API. In theory, I think I should be able to modify sys.path to be able to use rclpy. I tried to simply print sys.path in the command line, append these values to sys.path in a script run py Blender and then in the same script import rclpy. The script looks like this:
import sys
new = ['', '/root/ros2_foxy/ros2-linux/lib/python3.8/site-packages', '/usr/lib/python38.zip', '/usr/lib/python3.8', '/usr/lib/python3.8/lib-dynload', '/usr/local/lib/python3.8/dist-packages', '/usr/lib/python3/dist-packages']
for line in new:
if line not in sys.path:
sys.path.append(line) import rclpy
Which seems to work but when I try to do
from rclpy.node import Node
It gives this error message:
Traceback (most recent call last):
File "/home/test.blend/Text", line 42, inFile "/root/ros2_foxy/ros2-linux/lib/python3.8/site-packages/rclpy/node.py", line 41, in from rclpy.client import Client File "/root/ros2foxy/ros2-linux/lib/python3.8/site-packages/rclpy/client.py", line 22, in
from rclpy.impl.implementation singleton import rclpyimplementation as _rclpy File "/root/ros2foxy/ros2-linux/lib/python3.8/site-packages/rclpy/impl/implementationsingleton.py", line 31, inrclpy implementation = import('.rclpy') File "/root/ros2foxy/ros2-linux/lib/python3.8/site-packages/rclpy/impl/init.py", line 28, in _import return importlib.importmodule(name, package='rclpy') File "/usr/bin/2.93/python/lib/python3.9/importlib/init.py", line 127, in importmodule return _bootstrap.gcdimport(name[level:], package, level) ModuleNotFoundError: No module named 'rclpy.rclpy' The C extension '/root/ros2foxy/ros2-linux/lib/python3.8/site-packages/rclpy/rclpy.cpython-39-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 Error: Python script failed, check the message in the system console
So here's my question: How do I correctly import rclpy and all other needed components if I'm in a capsuled python environment?
PS: Sorry for the formatting, I don't know how to do it properly :b
Asked by TheBee on 2021-07-28 07:09:29 UTC
Comments
have a look at this link, and if you think it is duplicate then, please! close this question. https://answers.ros.org/question/355064/ros2-modulenotfounderror-no-module-named-rclpy_rclpy/
Asked by Ranjit Kathiriya on 2021-07-28 08:27:38 UTC
I've seen this question but in that case the python environment was different because of anaconda, in my case I have no conda environment to deactivate. I know I need to replicate the ros2 python environment, but I don't know how I can do that only using a Python script.
Asked by TheBee on 2021-07-29 01:42:44 UTC