I am using ROS2 on Windows. I am trying to build my my_robot_cpp package using colcon build. However, I get this error:
C:\Users\ken\ROS2\ros2_ws>colcon build --event-handlers desktop_notification-
Starting >>> my_robot_controller
Starting >>> my_robot_cpp
Finished <<< my_robot_controller [1.38s]
--- stderr: my_robot_cpp
Traceback (most recent call last):
File "C:\dev\ros2_humble\share\ament_cmake_core\cmake\core\package_xml_2_cmake.py", line 22, in <module>
from catkin_pkg.package import parse_package_string
ModuleNotFoundError: No module named 'catkin_pkg'
CMake Error at C:/dev/ros2_humble/share/ament_cmake_core/cmake/core/ament_package_xml.cmake:95 (message):
execute_process(C:/Users/ken/AppData/Local/Programs/Python/Python39/python.exe
C:/dev/ros2_humble/share/ament_cmake_core/cmake/core/package_xml_2_cmake.py
C:/Users/ken/ROS2/ros2_ws/src/my_robot_cpp/package.xml
C:/Users/ken/ROS2/ros2_ws/build/my_robot_cpp/ament_cmake_core/package.cmake)
returned error code 1
Call Stack (most recent call first):
C:/dev/ros2_humble/share/ament_cmake_core/cmake/core/ament_package_xml.cmake:49 (_ament_package_xml)
C:/dev/ros2_humble/share/ament_lint_auto/cmake/ament_lint_auto_find_test_dependencies.cmake:31 (ament_package_xml)
CMakeLists.txt:23 (ament_lint_auto_find_test_dependencies)
---
Failed <<< my_robot_cpp [2.12s, exited with code 1]
Summary: 1 package finished [2.41s]
1 package failed: my_robot_cpp
1 package had stderr output: my_robot_cpp
I see the error ModuleNotFoundError: No module named 'catkin_pkg' so I attempt to install it, but it says it is already installed:
C:\Users\ken\ROS2\ros2_ws>pip install -U catkin_pkg
Requirement already satisfied: catkin_pkg in c:\python38\lib\site-packages (0.5.2)
Collecting catkin_pkg
Obtaining dependency information for catkin_pkg from https://files.pythonhosted.org/packages/91/f7/86d933ec31f00450f513ef110fa9c0e5da4c6e2c992933a35c8d8fe7d01f/catkin_pkg-1.0.0-py3-none-any.whl.metadata
Downloading catkin_pkg-1.0.0-py3-none-any.whl.metadata (1.3 kB)
Requirement already satisfied: docutils in c:\python38\lib\site-packages (from catkin_pkg) (0.20.1)
Requirement already satisfied: python-dateutil in c:\python38\lib\site-packages (from catkin_pkg) (2.8.2)
Requirement already satisfied: pyparsing in c:\python38\lib\site-packages (from catkin_pkg) (2.4.7)
Requirement already satisfied: setuptools in c:\python38\lib\site-packages (from catkin_pkg) (41.2.0)
Requirement already satisfied: six>=1.5 in c:\python38\lib\site-packages (from python-dateutil->catkin_pkg) (1.16.0)
Downloading catkin_pkg-1.0.0-py3-none-any.whl (75 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 76.0/76.0 kB 2.1 MB/s eta 0:00:00
Installing collected packages: catkin_pkg
Attempting uninstall: catkin_pkg
Found existing installation: catkin-pkg 0.5.2
Uninstalling catkin-pkg-0.5.2:
Successfully uninstalled catkin-pkg-0.5.2
Successfully installed catkin_pkg-1.0.0
The issue I see now I believe is that that the catkin_pkg module is installed for Python 3.8, yet the command appears to be trying to use a different Python version (3.9) as evident in this line: execute_process(C:/Users/ken/AppData/Local/Programs/Python/Python39/python.exe
I also attempted to set the PYTHON_EXECUTABLE variable in the CMakeLists.txt file but it doesn't seem to do anything.
# Set the path to your Python executable
set(PYTHON_EXECUTABLE /C:/Python38/python.exe)
cmake_minimum_required(VERSION 3.8)
project(my_robot_cpp)
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic)
endif()
# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
if(BUILD_TESTING)
find_package(ament_lint_auto REQUIRED)
set(ament_cmake_copyright_FOUND TRUE)
set(ament_cmake_cpplint_FOUND TRUE)
ament_lint_auto_find_test_dependencies()
endif()
ament_package()
I saw this question already, it's similar to my problem however I didn't get any help.
Also, I checked the install\local_setup.bat file and it seems to be using the correct python executable so i really dont know where it is wrong.
:_colcon_run_ordered_commands
setlocal enabledelayedexpansion
:: check environment variable for custom Python executable
if "%COLCON_PYTHON_EXECUTABLE%" NEQ "" (
if not exist "%COLCON_PYTHON_EXECUTABLE%" (
echo error: COLCON_PYTHON_EXECUTABLE '%COLCON_PYTHON_EXECUTABLE%' doesn't exist
exit /b 1
)
set "_colcon_python_executable=%COLCON_PYTHON_EXECUTABLE%"
) else (
:: use the Python executable known at configure time
set "_colcon_python_executable=c:\python38\python.exe"
:: if it doesn't exist try a fall back
if not exist "!_colcon_python_executable!" (
python --version > NUL 2> NUL
if errorlevel 1 (
echo error: unable to find python executable
exit /b 1
)
set "_colcon_python_executable=python"
)
)