diff --git a/cmake/templates/generate_cached_setup.py.in b/cmake/templates/generate_cached_setup.py.in index bf9c37085..c2848e04c 100644 --- a/cmake/templates/generate_cached_setup.py.in +++ b/cmake/templates/generate_cached_setup.py.in @@ -4,10 +4,19 @@ import os import stat import sys -# find the import relatively if available to work before installing catkin or overlaying installed version +# find the import for catkin's python package - either from source space or from an installed underlay if os.path.exists(os.path.join('@catkin_EXTRAS_DIR@', 'catkinConfig.cmake.in')): sys.path.insert(0, os.path.join('@catkin_EXTRAS_DIR@', '..', 'python')) -from catkin.environment_cache import generate_environment_script +try: + from catkin.environment_cache import generate_environment_script +except ImportError: + # search for catkin package in all workspaces and prepend to path + for workspace in "@CATKIN_WORKSPACES@".split(';'): + python_path = os.path.join(workspace, '@CATKIN_GLOBAL_PYTHON_DESTINATION@') + if os.path.isdir(os.path.join(python_path, 'catkin')): + sys.path.insert(0, python_path) + break + from catkin.environment_cache import generate_environment_script code = generate_environment_script('@CATKIN_DEVEL_PREFIX@/env.@script_ext@')