Rosanswers logo

I am using ROS Kinetic with Ubuntu 16.04 LTS.

I am trying to connect two ROS nodes (publisher/subscriber, both of them). In one Python node, I am trying to use some modules I had already programmed, which are embedded in pyib2c module.

import pyib2c

This module also imports some Python modules. When I try to run my node, I receive the following error:

ImportError: cannot import name XXXXX , where XXXXX are the modules imported by my pyib2c module.

I have already uncommented the * catkin_python_setup() * in the CMakeList of my package. The setup.py is:

from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup

# fetch values from package.xml
setup_args = generate_distutils_setup(
    package_dir={'': 'src'})


I have also created a init.py file which is:

 from . import tabulate
 from . import pyib2c

My Python node, the module pyib2c, the init.py and the setup.py are them all at the same level in my_package/src. However, it turns out to display the same mistake if I keep the pyib2c in a src folder.

How can I make my node import the modules I need?

Originally posted by FerCipri on ROS Answers with karma: 21 on 2018-02-19

Post score: 2

Original comments

Comment by jayess on 2018-02-21:
Have you compiled your package? In order for you to use the module in your package catkin needs to run your setup.py.

Comment by FerCipri on 2018-02-21:
Yes, I have run catkin_make at my catkin_ws and it works perfectly. The trouble comes at the point of rosrun my node.


1 Answer 1


Rosanswers logo

The module (i.e. the source files) as well as the __init__.pyneeds to be placed in <path_to_your_package>/src/<your_package> (at least by convention and as explained in the documentation, it might work another way).

The setup.py needs to be in <path_to_your_package>.

Then catkin_python_setup should be able to find everything correctly and, hopefully, you should be able to import everything properly.

Originally posted by mgruhler with karma: 12390 on 2018-02-21

This answer was ACCEPTED on the original site

Post score: 2

Original comments

Comment by FerCipri on 2018-02-21:
I have tried as you said and didn't work. In fact, it stopped recognising my pyib2c python module =S

Comment by mgruhler on 2018-02-22:
Did you run catkin_make once more after reorganizing? You can check if it has been installed properly if the module can be found below devel/lib/python2.7/<yourpackage>, if i am correct.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.