Import rclpy in a capsuled python environment

asked 2021-07-28 07:09:29 -0600

TheBee gravatar image

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, in <module> File "/root/ros2_foxy/ros2-linux/lib/python3.8/site-packages/rclpy/node.py", line 41, in <module> from rclpy.client import Client

File "/root/ros2_foxy/ros2-linux/lib/python3.8/site-packages/rclpy/client.py", line 22, in <module> from rclpy.impl.implementation_singleton import rclpy_implementation as _rclpy File "/root/ros2_foxy/ros2-linux/lib/python3.8/site-packages/rclpy/impl/implementation_singleton.py", line 31, in <module> rclpy_implementation = _import('._rclpy') File "/root/ros2_foxy/ros2-linux/lib/python3.8/site-packages/rclpy/impl/__init__.py", line 28, in _import return importlib.import_module(name, package='rclpy') File "/usr/bin/2.93/python/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' The C extension '/root/ros2_foxy/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/Troubl...' for possible solutions Error: Python script failed, check the message in the system console</module></module>

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

edit retag flag offensive close merge delete

Comments

have a look at this link, and if you think it is duplicate then, please! close this question. https://answers.ros.org/question/3550...

Ranjit Kathiriya gravatar image Ranjit Kathiriya  ( 2021-07-28 08:27:38 -0600 )edit

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.

TheBee gravatar image TheBee  ( 2021-07-29 01:42:44 -0600 )edit