import rclpy without sourcing setup.bash

asked 2021-04-07 09:19:45 -0500

highmax1234 gravatar image

Hi,

I want to use the rclpy module in a python script. This script is called by a flask application which is invoked by an apache2 webserver and does not get the necessary bash context. When I run the python script from bash with python3 foo.py everything works fine, as I have . /opt/ros/foxy/setup.bash in my ~/.bashrc .

When the script gets invoked by flask and apache2, import rclpy is not found. Exeucting sys.path.insert("/opt/ros/foxy/lib/python3.8/site-packages/") brings another error:

The C extension '/opt/ros/foxy/lib/python3.8/site-packages/rclpy/_rclpy.cpython-38-x86_64-linux-gnu.so' failed to be imported while being present on the system. Please refer to 'https://index.ros.org/doc/ros2/Troubleshooting/Installation-Troubleshooting/#import-failing-even-with-library-present-on-the-system' for possible solutions

There has been a similar Thread with no solution. The essence seems to be that opt/ros/foxy/setup.bash does more than just setting paths.

Now, is there any possibilty to use rclpy in a python script without sourcing from bash? Thanks

Ubuntu 20.04
ROS2 foxy

edit retag flag offensive close merge delete