Exercise 4.3 ROS Basics Python

Was there an error from the user end?

Hi @maanvisingh,

I created a package and created a message named Age.msg just like you did to reproduce the error you are experiencing.

I then created a file named age_pub.py and put the content you shared here and it failed for the same reason.

I then tried to fiind a file named Age.py in my ~/catkin_ws (which should have been generated when we run catkin_make) but could not find it, which left me thinking :thinking:.

I then checked the ~/catkin_ws/devel/lib/python3/dist-packages/my_examples_pkg/msg/ folder, and for my surprise, I found that the generated file was named “_Age.py” instead of “Age.py”. I have no idea why this happened.

But to solve the issue, I just copied the _Age.py file to Age.py

 
cp -v ~/catkin_ws/devel/lib/python3/dist-packages/my_examples_pkg/msg/_Age.py ~/catkin_ws/devel/lib/python3/dist-packages/my_examples_pkg/msg/Age.py

After that, running python age_pub.py worked.

Again, I don’t know why the generated file was named _Age.py instead of Age.py, but copying it to Age.py solved the problem in my tests.

I cannot find a folder named python3 in ~/catkin_ws/devel/lib/

image

I tried creating a new package and following everything step by step from the solution for the exercise but I am still facing the same issue.

Hi @maanvisingh ,

the ~/catkin_ws/devel/lib/python3 is only created when you do a catkin_make

cd ~/catkin_ws
catkin_make
# Now, the ~/catkin_ws/devel/lib/python3 folder should exist if 
# you are compiling messages, services or actions.

If it does not exist even after catkin_make, could you tell us which folders exist under “~/catkin_ws/devel/lib” ?

After running catkin_make also

image

I have the exact same problem. I have followed the solutions, doublechecked and pasted in the answer from the solution. But it still wont find my file (in my case the file name is :exercise_33)

Even if i ignore the error in the IDE I still get an error when running roslaunch in the terminal.

Hoping for a fast reply.
Draceri

@Draceri

In your case, you need to write:

from exercise_33.msg import Age

The custom files are always generated in devel, not directly within the working directories of the package. They are always generated in the exact place where you found the _Age.py file.

This is normal. In _Age.py you have the class Age, and in __init__.py (in the same msg directory) you have:

from _Age import *

so the Age class is available from my_examples_pkg.msg.

This is not necessary. I also saw the same thing but didn’t have to do that. Like I showed above, the Age class is available via import from _Age.py.

@maanvisingh

This is very very very strange! Should not happen if catkin_make ran successfully and your custom message is properly setup. Please try:

cd ~/catkin_ws
rm -rf build/ devel/
catkin_make
source devel/setup.bash

If this does not work, record a video of everything and give us a link here.

1 Like

No, this does not have any effect. It still can’t find my file.

ModuleNotFoundError: No module named ‘exercise_33’

Then please record a short screencast to show us what is happening in your workspace, showing your package structure and content of the files. Then please follow this post and include the result in your video.

What you wrote before:

from exercise_33 import Age
# it should be 
# from exercise_33.msg import Age

was a bug. Perhaps there are other bugs.

It worked now. After i did catkin_make and source devel/setup.bash. It all worked.

But the error still persist in the IDE screen

Thanks for the feedback. We have fixed the error in the IDE and it’s currently syncing across our VM and might take some time to be available on all.

Hi @maanvisingh,

if you don’t have a python3 folder inside ~/catkin_ws/devel/lib, then is very likely that your package/workspace was first compiled with catkin build instead of catkin_make.

So, the solution would be to remove the devel and build folders before running catkin_make as @bayodesegun suggested.

cd ~/catkin_ws
rm -rf build/ devel/
catkin_make
source devel/setup.bash

This topic was automatically closed after 4 days. New replies are no longer allowed.