0
$\begingroup$

Rosanswers logo

Hello everyone. I migrate an installation from one computer to another, switching from Ubuntu 12.04 to 16.04 and from indigo ros to kinetic When I run my installation that has about 30 packages most of the things seem to start well except for a package that fails to make an import I specify that I do not have this error on the computer of the previous configuration, or everything is identical in my programs, except the denomination of indigo and kinetic The error is as follows:

From my_folder_msgs.msg import my_file as My_fileMsg   
ImportError : No module named my_folder_msgs.msg 

Of course, my_folder_msgs.msg exists and appears when I call: rosmsg list.

Would anyone have an idea?


Originally posted by pibauer on ROS Answers with karma: 21 on 2017-09-27

Post score: 2


Original comments

Comment by Nico__ on 2017-09-27:
Hi, Make sure you got the "#!/usr/bin/env python" line at top of your python file, also make sure that youre customs messages are built. You can check with rosmsgs list | grep your_custom_msgs

Nicolas

Comment by pibauer on 2017-09-29:
Thank you for your message. everything was as you advised

Comment by [email protected] on 2020-06-10:
https://www.theconstructsim.com/solve-error-importerror-no-module-named-xxxx-msg-2/

$\endgroup$

2 Answers 2

0
$\begingroup$

Rosanswers logo

Hi @pibauer,

when we use our custom messages, even if they are listed with rosmsg list, they only can be used by our nodes after they be compiled.

I have created a video (https://youtu.be/NKeebwRNvv8) that answers exactly this question.

The steps explained in the video are basically the following:

  1. You have to compile your message. For that, you have to touch the package.xml and CMakeLists.txt according to the instructions found on CMakeLists.txt. After prepare the package.xml and CMakeLists.txt, you run catkin_make on your catkin_ws

  2. After the message is compiled, you have to source the setup.bash like: source catkin_ws/devel/setup.bash

  3. Now you can import your messages without any problem.

That is it. If you still have any questions, just ask here or watch the video aforementioned.


Originally posted by Ruben Alves with karma: 1038 on 2017-09-29

This answer was ACCEPTED on the original site

Post score: 3


Original comments

Comment by pibauer on 2017-09-29:
your video is super clear. thank you for that clarification

Comment by Ruben Alves on 2017-09-29:
You're Welcome.

Great to know that it helped.

If you can, just mark the answer as correct.

Cheers.

Comment by navibot on 2018-03-18:
Thanks this helped me too! Just remember to load a new terminal or resource the setup script after compilation.

$\endgroup$
0
$\begingroup$

Rosanswers logo

For those that don't like to watch videos and want an answer straightaway (this is taken right from the wiki):

Update your package.xml with:

<build_depend>message_generation</build_depend>
<exec_depend>message_runtime</exec_depend>

This will tell the build system about the new message definitions.

Next, modify your CMakeLists.txt file by:

adding the following at the end of find_package()

find_package(
    ...
    # any packages your messages depend on such as std_msgs
    message_generation
)

export the message runtime dependency

catkin_package(
  ...
  CATKIN_DEPENDS message_runtime ...
  ...)

add any message files that you have defined and want to compile

add_message_files(
  FILES
  my_file.msg
)

call the generate_messages() function

generate_messages(
  DEPENDENCIES
  std_msgs
  # and any other packages your messages depend on
)

Now, navigate to your workspace's root and compile using either

~/catkin_ws/$ catkin_make

or

~/catkin_ws/$ catkin build

and source your workspace

~/catkin_ws/$ source devel/setup.bash

Originally posted by jayess with karma: 6155 on 2019-04-04

This answer was NOT ACCEPTED on the original site

Post score: 3

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.