ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

"ImportError no module named" error when package with msg also has setup.py and installed

asked 2017-05-01 20:14:27 -0500

lucasw gravatar image

updated 2020-11-21 12:16:48 -0500

I have a package with a foo.msg and a python module my_package/src/my_package/bar.py that works fine in the devel space- I can import the msg or alternatively import the python module just fine. But after running catkin_make install the I get an import error:

catkin_make install
source devel/setup.bash
python
>>>> from mypackage.msg import Foo
>>>>
>>>>  # (no error output, worked fine)
source install/setup.bash
>>>> from mypackage.msg import Foo
Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
Import Error: No module named my_package.msg

I commented out the catkin_python_setup from the CMakeLists.txt and rebuilt (rm -rf build devel install followed by source /opt/ros/jade/setup.bash seems safest which maybe ought to become the topic of another question...), then the import works fine.

One thing I notice is that the module bar.py is installed into install/lib/python2.7/dist-packages/my_package, and there are no __init__.py files in that directory, only one directory lower in msg (it contains __init__.py and _Foo.py and pyc versions).

This is jade with Ubuntu 14.04.

edit retag flag offensive close merge delete

Comments

Actually now that I try it the importing of bar isn't working in the devel space either, so that being configured wrong may be a component of the problem.

lucasw gravatar image lucasw  ( 2017-05-01 20:18:18 -0500 )edit

my_package/src/my_package/ was missing __init__.py, added it and now this works: from my_package.bar import bar

lucasw gravatar image lucasw  ( 2017-05-01 20:21:44 -0500 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2017-05-01 20:28:56 -0500

lucasw gravatar image

updated 2017-05-02 10:08:52 -0500

The answer is to make sure that my_package/src/my_package/__init__.py exists, otherwise it can't import that module but also screws up msg modules from the same package when installed.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2017-05-01 20:14:27 -0500

Seen: 2,307 times

Last updated: May 02 '17