Skip to content

Instantly share code, notes, and snippets.

@whateverforever
Created September 15, 2021 08:27
Show Gist options
  • Save whateverforever/84153784d9b194d0a7db255a34120262 to your computer and use it in GitHub Desktop.
Save whateverforever/84153784d9b194d0a7db255a34120262 to your computer and use it in GitHub Desktop.
CMake vscode extension doesn't configure ROS project - ImportError: No module named catkin

ImportError: No module named catkin

generate_cached_setup.py:

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 ''.split(';'):
        python_path = os.path.join(workspace, 'lib/python3/dist-packages')
        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

The issue is the ''.split(). What is missing here is a list of paths separated by semicolons. Which path list? CMAKE_PREFIX_PATH!

So, in case your vscode cmake extension doesn't configure your ros projects, make sure the CMAKE_PREFIX_PATH includes ROS. Also make sure the semicolon is escaped (only once, if you do it in the vscode gui, twice if in json):

"cmake.configureEnvironment": {
    "CMAKE_PREFIX_PATH": "/home/user/code/devel\\;/opt/ros/noetic"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment