Exercise 4.3 ROS Basics Python

Thanks for pointing this out but the same error still persists.

  1. can you confirm that the Age.msg file exist in a folder called msg in the package my_examples_pkg?

2.Share the following outputs:

rosmsg info Age

  1. Share the following’s output:

rospack list | grep my_examples_pkg

4.Also try running the python program after running the following command (this updates the package list)

rospack profile

  1. image
  1. Still the same error even after running rospack profile

The link mentioned above got into the same problem as yours. so from the articles try the following:

Go to the catkin_ws directory and run commands:
rm -rf build/ devel/
Now compile as shown.

After compilation, try running the program again to check if problem persist.

1 Like

Yes I tried this already still facing the same error.

@maanvisingh , Unfortunatly,i am not able to figure it out, i am forwarding your query to more experienced personal, they should be able to solve this.

Also, i dont know if this makes a difference, but your python file is outside the src folder, move it into the src folder and try compiling and sourcing.

2 Likes

Did you run source devel/setup.bash on EVERY shell? You should run this for every shell, not just the one where you ran catkin_make.

You may ignore the error in the IDE as long as you can launch your package from the web shells (terminals).

I am just using one shell where I compiled and sourced the files. Even if I am doing it through a launch file the programming is terminating with the same error as shown above.

Did you do this? The file should be in my_examples_pkg/src.

yes I tried that but it didnt help

I can confirm that this appears to be a linting false positive in the IDE (I apologize for this glitch), but it this error would not happen if everything is correctly done and run from the terminals, using python or roslaunch (I confirmed the same exercise you are doing here).

Please see this post.

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