Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I had the same issue but I was using pybind11 to make my python wrapper. The problem is that the PYTHONPATH is updated by addition bash files in each package (located in the share/<package>/hooks folder), which get built if you depend on ament_python. However, if you are using CMake, you can't have two build types ament_cmake and ament_python, which means the PYTHONPATH isn't sourced properly. I found this tutorial helpful for building a dual CMake and Python package. There are two additional things you will have to do:

  1. Make sure to install the python wrapper in the correct directory. The default path for ROS2 is install/<package>/lib/python3.8/site-packages as opposed to the old python3/dist-packages
  2. Make sure that your exported wrapper is not the same name as your package name. I had a problem importing my wrapper when they were named the same, but once I changed my wrapper name, everything imported fine in Python.