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

Colcon select Python version

asked 2023-05-19 09:51:59 -0500

Deric gravatar image

updated 2023-06-02 08:43:27 -0500

Hello, I encountered problems while setting up Github Actions for a ROS2 Humble project on Windows. I used an action for setting up ROS2 since it seemed pretty complicated on Windows which uses Python version 3.7.

The problem is that colcon selects Python version 3.11 and fails with ModuleNotFoundError: No module named 'catkin_pkg' when building packages.

I tried using -DPYTHON_EXECUTABLE=... or Pythons`s virtual environments and created an issue at the repository containing the action which contains links to the workflow and logs, does anybody know a way of forcing colcon to use a particular Python version?

Edit: I also tried replacing the actions and doing everything by my self but the error persists.

2023-05-05T14:34:04.6016022Z Starting >>> dotnet_cmake_module
2023-05-05T14:34:04.7077082Z Starting >>> ament_cmake_export_assemblies
2023-05-05T14:34:05.9151305Z Not searching for unused variables given on the command line.
2023-05-05T14:34:05.9152542Z Not searching for unused variables given on the command line.
2023-05-05T14:34:21.1725257Z -- Found ament_cmake_core: 1.3.3 (C:/dev/humble/ros2-windows/share/ament_cmake_core/cmake)
2023-05-05T14:34:21.1726025Z -- Found ament_cmake: 1.3.3 (C:/dev/humble/ros2-windows/share/ament_cmake/cmake)
2023-05-05T14:34:42.3629746Z -- Found Python3: C:/hostedtoolcache/windows/Python/3.11.3/x86/python3.exe (found version "3.11.3") found components: Interpreter 
2023-05-05T14:34:42.3630442Z [Processing: ament_cmake_export_assemblies, dotnet_cmake_module]
2023-05-05T14:34:42.3631019Z -- Found Python3: C:/hostedtoolcache/windows/Python/3.11.3/x86/python3.exe (found version "3.11.3") found components: Interpreter 
2023-05-05T14:34:42.6704445Z Traceback (most recent call last):
2023-05-05T14:34:42.6705318Z   File "C:\dev\humble\ros2-windows\share\ament_cmake_core\cmake\core\", line 22, in <module>
2023-05-05T14:34:42.6705850Z     from catkin_pkg.package import parse_package_string
2023-05-05T14:34:42.6706309Z ModuleNotFoundError: No module named 'catkin_pkg'
edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted

answered 2023-05-19 14:14:55 -0500

jdlangs gravatar image

updated 2023-06-02 11:45:09 -0500

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.

edit flag offensive delete link more


Thank you for your response, but sadly running colcon with python -m colcon does not prevent the wrong Python version (3.11) from being selected when building packages.

Deric gravatar image Deric  ( 2023-05-24 11:40:48 -0500 )edit

That would indicate your python command points to a 3.11 version, which you can double check with python --version. So you need to sort out calling the version you actually want.

jdlangs gravatar image jdlangs  ( 2023-05-25 09:55:56 -0500 )edit

python --version returns the version which I installed (3.7.9)

Deric gravatar image Deric  ( 2023-05-26 10:56:15 -0500 )edit

Perhaps you can post more details/logs on how you know a different python version is involved?

jdlangs gravatar image jdlangs  ( 2023-05-31 08:57:33 -0500 )edit

I added the part of the log which contains the selected Python version and the error, the full log is available at the Issue which I linked.

Deric gravatar image Deric  ( 2023-06-02 08:44:43 -0500 )edit

Thanks for the log info, that cleared things up quite a bit. It would have been nice to have that pasted from the start. Reviewing an attached zip file of logs on a linked issue is a bit much to ask from question answerers.

jdlangs gravatar image jdlangs  ( 2023-06-02 11:54:18 -0500 )edit

Sorry, I will try to be more forthcoming next time

Deric gravatar image Deric  ( 2023-06-07 11:18:01 -0500 )edit

Hey did you guys end up solving this issue? I am stuck on it now

rakin374 gravatar image rakin374  ( 2023-07-21 23:38:10 -0500 )edit

Question Tools



Asked: 2023-05-19 09:51:59 -0500

Seen: 1,263 times

Last updated: Jun 02 '23