@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.
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.
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).
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 .
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
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.
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.
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