Exporting Python Module With Same Name as Package, with srv/msg
EDIT: MWE can be found here.
Per [1] and [2], I'm trying to export a python module that is the same name as the package:
packagename
CMakeLists.txt
package.xml # catkin_python_setup()
setup.py # generate_distutils_setup( ..., packages=['packagename'], ... )
|- src/
|- application.py # import packagename
|- packagename/
|- __init__.py
|- stuff.py
|- ...
This works as expected, no problem. However, if I introduce a service message and try to import it:
packagename
CMakeLists.txt
package.xml
setup.py
|- srv/
|- MySrv.srv
|- src/
|- application.py # import packagename
|- packagename/
|- __init__.py
|- stuff.py
|- use_my_service.py # from packagename.srv import MySrv
|- ...
At runtime I get
ImportError: No module named srv
It works if I change the name of the exported module:
packagename
CMakeLists.txt
package.xml
setup.py # generate_distutils_setup( ..., packages=['notpackagename'], ... )
|- srv/
|- MySrv.srv
|- src/
|- application.py # import notpackagename
|- notpackagename/
|- __init__.py
|- stuff.py
|- use_my_service.py # from notpackagename.srv import MySrv
|- ...
The path in both cases is exactly the same, including
$WORKSPACE_ROOT/devel/lib/python2.7/dist-packages
And in both cases I can locate the appropriate pacakgename/srv/_MySrv.py
. In the working case, the output directory structure looks like:
devel/lib/python2.7/dist-packages/
|- notpackagename
|- __init__.py # Non-empty, dist-utils generated
|- packagename
|- __init__.py # Empty.
|- srv/
|- __init__.py
|- _MySrv.py
And in the non-working case:
devel/lib/python2.7/dist-packages/
|- packagename
|- __init__.py # Non-empty, dist-utils generated.
|- srv/
|- __init__.py
|- _MySrv.py
It appears that the generated __init__.py
for the exported module clobbers the knowledge of the existence of submodules, but I'm not sure, I'm not particularly familiar with how catkin does it's magic for this.
Is my expectation for this to work misguided? If it's not supposed to/going to work, what is the preferred method? To prefix the module with lib
, as in [3] ?
What exact command are you invoking when you get the ImportError? Do you invoke src/application.py as a script / node?
The exception is raised right at import-time, in
use_my_service.py
(part of the module). The specific line looks likefrom packagename.srv import MySrv
.The
src/application.py
is called as a node, viaroslaunch
, with a simple.launch
file.See https://github.com/tfurf/rospy-srv-mo... for both working and non-working versions.