How do I install a Python module with a different name than the catkin package?
My package is named camera_info_manager_py, but the Python module is camera_info_manager.
With rosbuild that was easy: just create a src/camera_info_manager.py
script, and dependent packages could import it directly.
With catkin I can't figure out how to make it work. For API compatibility with earlier releases, I prefer not to rename the module camera_info_manager_py (which does work).
I suppose I could add that module to the camera_info_manager package, and make camera_info_manager_py depend on it for compatibility. But, that would be a hassle, and not relevant to the many users of the C++ camera_info_manager package.
EDIT: Thanks, William. I had tried the py_modules, and as you noted, it did not work. I didn't realize that was caused by a missing feature.
I do not fully understand your recommended work-around. Would the script go in src/camera_info_manager.py, as it did before? I was not able to figure out how to resolve that in the PYTHONPATH.
For compatibility, other packages need to do this:
import camera_info_manager
cinfo = camera_info_manager.CameraInfoManager()
or:
from camera_info_manager import *
cinfo = CameraInfoManager()
I still don't see how to make that happen.
EDIT2: I did (almost) exactly as you recommended, but catkin installs no camera_info_manager package.
$ roscd
$ catkin_make
$ cd build
$ make install
$ ls -l ../install/lib/python2.7/dist-packages/
total 20
drwxr-xr-x 3 joq joq 4096 Mar 26 16:59 ackermann_msgs
-rw-rw-r-- 1 joq joq 421 Mar 26 16:59 camera_info_manager_py-0.2.0.egg-info
drwxrwxr-x 2 joq joq 4096 Mar 26 16:59 unique_id
-rw-rw-r-- 1 joq joq 276 Mar 26 16:59 unique_id-1.0.1.egg-info
drwxr-xr-x 3 joq joq 4096 Mar 26 16:59 uuid_msgs
So, there is an egg-info for camera_info_manager_py, but no Python package.
$ make run_tests_camera_info_manager_py
-- run_tests.py: execute commands
/opt/ros/groovy/bin/rostest --pkgdir=/home/joq/ros/wet/groovy/src/camera_info_manager_py --package=camera_info_manager_py --results-filename tests_unit_test.xml /home/joq/ros/wet/groovy/src/camera_info_manager_py/tests/unit_test.test
... logging to /home/joq/.ros/log/rostest-vision-4-5760.log
[ROSUNIT] Outputting test results to /home/joq/ros/wet/groovy/build/test_results/camera_info_manager_py/rostest-tests_unit_test.xml
Traceback (most recent call last):
File "/home/joq/ros/wet/groovy/src/camera_info_manager_py/tests/test_camera_info_manager.py", line 17, in <module>
from camera_info_manager import *
ImportError: No module named camera_info_manager
testtest_camera_info_manager_py ... FAILURE!
As you can see, the from camera_info_manager import *
fails.
The only difference with what you recommended is that my src/camera_info_manager/__init__.py
contains only this:
from .camera_info_manager import *
I did it that way because the camera_info_manager module was already careful not to define anything not needed by its users. I guess it is equivalent to putting the entire script inside __init__.py.
EDIT3: here's my current setup.py:
#!/usr/bin/env python
from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup
d = generate_distutils_setup(
py_modules=['camera_info_manager'],
package_dir={'': 'src'},
install_requires=['yaml'],
)
setup(**d)
EDIT4: yes, the install did show these errors:
+ cd /home/joq/ros/wet/groovy/src/camera_info_manager_py
+ /usr/bin/env PYTHONPATH=/home/joq/ros/wet/groovy/install/lib/python2.7/dist-packages:/home/joq/ros/wet/groovy/build/lib ...
Is your repository up-to-date? https://github.com/jack-oquin/camera_info_manager_py/blob/master/setup.py Or is this an old setup.py
That is the old one. I have not committed these changes, because they don't work. The github one (which works) provides the camera_info_manager_py name, instead.
I could commit them to a new branch, if you want to experiment with it.
Your setup.py should be
packages=['camera_info_manager']
notpy_modules=['camera_info_manager']
. Can you post the output fromcatkin_make install
? I bet it has a message about not finding a py_module 'camera_info_manager'.Changing it to packages worked! Now the tests run successfully, and the
src/camera_info_manager
directory contents get installed under dist-packages. Thanks for the help, William!