Skip to content

Commit 9a570b3

Browse files
author
Felix Widmaier
committed
Finally solved the path problem
By changing the output directory for the wrapper module, it is now stored within the PYTHONPATH and thus is found by `import` without setting any path manually.
1 parent 4421ccc commit 9a570b3

File tree

4 files changed

+28
-13
lines changed

4 files changed

+28
-13
lines changed

CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ find_package(PythonLibs REQUIRED) # sets ${PYTHON_INCLUDE_DIRS}
1818
## Uncomment this if the package has a setup.py. This macro ensures
1919
## modules and global scripts declared therein get installed
2020
## See http://ros.org/doc/api/catkin/html/user_guide/setup_dot_py.html
21-
# catkin_python_setup()
21+
catkin_python_setup() # this sets up the path /devel/lib/python2.7/dist-packages/boostpy_test
2222

2323

2424

@@ -54,6 +54,10 @@ include_directories(
5454
add_library(mycpplib SHARED
5555
src/mycpplib.cpp
5656
)
57+
# change output directory, so python can find the module
58+
set_target_properties(mycpplib PROPERTIES
59+
LIBRARY_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_PYTHON_DESTINATION}
60+
)
5761

5862
target_link_libraries(mycpplib
5963
${catkin_LIBRARIES}

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,13 @@ This page looks like a very nice and detailed tutorial: https://www.preney.ca/pa
77

88
Maybe even better:
99
https://github.com/ethz-asl/Schweizer-Messer/wiki/Adding-boost::python-exports-to-your-ROS-package
10+
11+
Form http://wiki.ros.org/catkin/CMakeLists.txt:
12+
7.2 Custom output directory
13+
While the default output directory for executables and libraries is usual set to a reasonable
14+
value it must be customized in certain cases. I.e. a library containing Python bindings must be
15+
placed in a different folder to be importable in Python:
16+
17+
set_target_properties(python_module_library PROPERTIES
18+
LIBRARY_OUTPUT_DIRECTORY ${CATKIN_DEVEL_PREFIX}/${CATKIN_PACKAGE_PYTHON_DESTINATION}
19+
)

scripts/use_cpplib.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,7 @@
11
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
3-
4-
import rospy
5-
6-
import sys
7-
# TODO: this is ugly... can this be set using cmake?
8-
sys.path.append("/home/felix/ws/ros/devel/lib")
9-
10-
import libmycpplib as cpp
3+
import boostpy_test.libmycpplib as cpp
114

125
# this is the equivalent to `main()` in c++
136
if __name__ == '__main__':
14-
rospy.init_node('use_cpplib')
15-
167
cpp.hello()
17-
18-
#rospy.spin()

setup.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
## ! DO NOT MANUALLY INVOKE THIS setup.py, USE CATKIN INSTEAD
2+
3+
from distutils.core import setup
4+
from catkin_pkg.python_setup import generate_distutils_setup
5+
6+
# fetch values from package.xml
7+
setup_args = generate_distutils_setup(
8+
packages=['boostpy_test'],
9+
package_dir={'': 'src'},
10+
)
11+
12+
setup(**setup_args)

0 commit comments

Comments
 (0)