Bogdan Fateev
Bogdan Fateev

Reputation: 33

How to import Webots controller in a Ros-python script

I want to write a controller in Python and trying to import Webots controller library:

#!/usr/bin/env python

import rospy
from std_msgs.msg import String
from time import sleep
from controller import Robot

and get the error

Traceback (most recent call last):
  File "./mine_controller.py", line 6, in <module>
    from controller import Robot
  File "/snap/webots/current/usr/share/webots/lib/controller/python27/controller.py", line 17, in <module>
    _controller = swig_import_helper()
  File "/snap/webots/current/usr/share/webots/lib/controller/python27/controller.py", line 16, in swig_import_helper
    return importlib.import_module('_controller')
  File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: libCppController.so: cannot open shared object file: No such file or directory

My environmental variables :

PYTHONPATH=/snap/webots/current/usr/share/webots/lib/controller/python27:/home/boand/workspace_ros/devel/lib/python2.7/dist-packages:/opt/ros/melodic/lib/python2.7/dist-packages
LD_LIBRARY_PATH=/home/boand/workspace_ros/devel/lib:/opt/ros/melodic/lib:/snap/webots/current/usr/share/webots/lib

Upvotes: 2

Views: 636

Answers (1)

David Mansolino
David Mansolino

Reputation: 1733

It seems your LD_LIBRARY_PATH is wrong, /snap/webots/current/usr/share/webots/lib should be replaced by /snap/webots/current/usr/share/webots/lib/controller.

Upvotes: 2

Related Questions