ModuleNotFoundError: No module named 'ament_package'
Hello! I am using ROS2 dashing for building my program. I also have ROS Melodic in my system. For ROS2 instead of sourcing, the environment from source /opt/ros/dashing/setup.bash I am setting the CMAKEPREFIXPATH in CMakeLists.txt.
SET(CMAKE_PREFIX_PATH "${CMAKE_REFIX_PATH} home/pankhuri/ros2_ws/install;/opt/ros/dashing")
While building with colcon build --symlink-install My code works well but now since I have to avoid sourcing the path I am getting this error:
pankhuri@pankhuri-LENOVO-IDEAPAD-500-15ISK:~/week2$ colcon buildStarting >>> dummyexample
--- stderr: dummyexample
Traceback (most recent call last):
File "/opt/ros/dashing/share/ament_cmake_core/cmake/package_templates/templates_2_cmake.py", line 21, in <module>
from ament_package.templates import get_environment_hook_template_path
ModuleNotFoundError: No module named 'ament_package'
CMake Error at /opt/ros/dashing/share/ament_cmake_core/cmake/ament_cmake_package_templates-extras.cmake:41 (message):
execute_process(/usr/bin/python3
/opt/ros/dashing/share/ament_cmake_core/cmake/package_templates/templates_2_cmake.py
/home/pankhuri/week2/build/dummyexample/ament_cmake_package_templates/templates.cmake)
returned error code 1
Call Stack (most recent call first):
/opt/ros/dashing/share/ament_cmake_core/cmake/ament_cmake_coreConfig.cmake:38 (include)
/opt/ros/dashing/share/ament_cmake/cmake/ament_cmake_export_dependencies-extras.cmake:15 (find_package)
/opt/ros/dashing/share/ament_cmake/cmake/ament_cmakeConfig.cmake:38 (include)
CMakeLists.txt:13 (find_package)
---
Failed <<< dummyexample [ Exited with code 1 ]
Summary: 0 packages finished [0.36s]
1 package failed: dummyexample
1 package had stderr output: dummyexample
Some Snippets of my CMakeLists.txt are:
cmake_minimum_required(VERSION 3.5)
project(dummyexample)
#Default to C++14
if(NOT CMAKE_CXX_STANDARD)
set(CMAKE_CXX_STANDARD 14)
endif()
if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wall -Wextra -Wpedantic -Wunused-parameter)
endif()
SET(CMAKE_PREFIX_PATH "${CMAKE_REFIX_PATH} home/pankhuri/ros2_ws/install;/opt/ros/dashing")
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
include_directories(
include
${rclcpp_INCLUDE_DIRS}
)
add_executable(main main.cpp)
target_link_libraries(main ${rclcppLIBRARIES} ${std_msgs_LIBRARIES} )
install(TARGETS main
DESTINATION bin)
Any suggestion in this matter would be helpful..
Asked by petal on 2019-06-09 09:29:19 UTC
Comments
can you clarify why?
Asked by gvdhoorn on 2019-06-09 10:00:38 UTC
ament_package
is a Python module. Python uses thePYTHONPATH
variable. It doesn't retrieve theCMAKE_PREFIX_PATH
, so setting is will not extend the Python search path.Asked by gvdhoorn on 2019-06-09 10:01:40 UTC
I am working on extending the support of some tools to ROS2 in such a way that they are compatible with both ROS1 and ROS2. So, I have to get both ROS1 and ROS2 libraries in CMakeLists.txt for compiling conditionally.
Setting CMAKE_PREFIX_PATH for ROS1 worked well without the need of sourcing the ROS Melodic. I wanted to do something similar for ROS2 too. I Understood why setting the CMAKE_PREFIX_PATH won't work for it. Can you suggest any alternative for this?
Asked by petal on 2019-06-09 10:27:00 UTC
As long as none of your ROS nodes are
rospy
based orroscpp
based and need additional libraries, this could work. The environment will not be correctly setup though (missingROS_MASTER_URI
,ROS_HOME
,LD_LIBRARY_PATH
,ROS_DISTRO
,ROS_VERSION
,ROS_PACKAGE_PATH
and a nr of other variables).Asked by gvdhoorn on 2019-06-09 11:15:54 UTC
My ROS does have cpp file (rclcpp), which gives error here..
Asked by petal on 2019-06-09 14:45:14 UTC
The error is in a Python script, which can't
import
a certain Python module. The problem is inament_cmake_core
, not in your node.Asked by gvdhoorn on 2019-06-09 14:48:33 UTC
I set the pythonpath first and then CMake_PREFIX_PATH with:
And this problem got solved.
Asked by petal on 2019-06-10 01:11:33 UTC
Unless really necessary, I would recommend to not manually mutate these sort of environment variables.
Asked by gvdhoorn on 2019-06-10 01:50:07 UTC