ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Colcon doesn't "select" a python version. Like all python tools, it uses the version of the environment it was installed into. The script that runs when you invoke colcon as an executable command is a python file generated in the install process and its first line is a shebang pointing to the python interpreter of the environment. On Ubuntu, when you do apt install python3-colcon it points to /usr/bin/python3 since it's using the global system environment. But you can also pip install it in other places (like a virtual env) and then it will point to that interpreter instead. Or alternatively, if you have a python environment which can see the installed colcon packages (like a virtual env which can see system packages), you can run colcon inside that environment through it's interpreter directly via python -m colcon.

Based on the log information, it's clear this is unrelated to colcon; it's CMake that's finding the wrong version of python when building the ament_cmake_export_assemblies package. The script that fails is invoked from inside the call to ament_package and it seems to use the version of python found here which happens when find_package(ament_cmake) is called. Looking at the CMake docs for finding Python, it looks like the main way to control which one is found is via the Python3_ROOT_DIR variable. You could try to set it to the one you want as a --cmake-arg in the colcon invocation or via colcon.pkg file for that package specifically.


Original answer:

Colcon doesn't "select" a python version. Like all python tools, it uses the version of the environment it was installed into. The script that runs when you invoke colcon as an executable command is a python file generated in the install process and its first line is a shebang pointing to the python interpreter of the environment. On Ubuntu, when you do apt install python3-colcon it points to /usr/bin/python3 since it's using the global system environment. But you can also pip install it in other places (like a virtual env) and then it will point to that interpreter instead. Or alternatively, if you have a python environment which can see the installed colcon packages (like a virtual env which can see system packages), you can run colcon inside that environment through it's interpreter directly via python -m colcon.