UNIT 4 ImportError: No module named action

Hello everyone,

I tried to make the quiz of the UNIT 4 but I have the following error :

ROS_MASTER_URI=http://master:11311

process[move_drone_up_down-1]: started with pid [21804]
Traceback (most recent call last):
File “/home/user/catkin_ws/src/actions_quiz/src/actions_quiz.py”, line 6, in
from actions_quiz.action import CustomActionMsgFeedback, CustomActionMsgResult, CustomActionMsgAction
File “/home/user/catkin_ws/src/actions_quiz/src/actions_quiz.py”, line 6, in
from actions_quiz.action import CustomActionMsgFeedback, CustomActionMsgResult, CustomActionMsgAction
ImportError: No module named action
[move_drone_up_down-1] process has died [pid 21804, exit code 1, cmd /home/user/catkin_ws/src/actions_quiz/src/actions_quiz.py __name:=move_drone_up_down __log:=/home/user/.ros/log/89077374-3d13-11ea-bbe0-0afd0f4a4f44/move_drone_up_down-1.log].
log file: /home/user/.ros/log/89077374-3d13-11ea-bbe0-0afd0f4a4f44/move_drone_up_down-1*.log
all processes on machine have died, roslaunch will exit
shutting down processing monitor…
… shutting down processing monitor complete
done

You can find below the beginning of my code :

#! /usr/bin/env python

import rospy

import time

import actionlib

from actions_quiz.action import CustomActionMsgFeedback, CustomActionMsgResult, CustomActionMsgAction

from std_msgs.msg import Empty

I tried a lot of things but now, with 3 hours approximately of looking for a solution, I’m asking for some help.

I can share my code in PM of course

Please share here your code so that we may be able to debug. Please tell us the course, unit and commands to reproduce.

Thank you for your answer,

you can find below my launch :

launch
node pkg=“actions_quiz” type=“actions_quiz.py” name=“move_drone_up_down” output=“screen” /
/launch

PS : For uknown reasons, I can’t use the signs < and > when I’m writing here…

my action file:

string goal



string feedback

my py file :

#! /usr/bin/env python
import rospy
import time
import actionlib

from actions_quiz.action import CustomActionMsgFeedback, CustomActionMsgResult, CustomActionMsgAction
from std_msgs.msg import Empty

class MoveUpDownClass(object):

_feedback = CustomActionMsgFeedback()
_result = CustomActionMsgResult()
def init(self):
# creates the action server
self._as = actionlib.SimpleActionServer(“action_custom_msg_as”, CustomActionMsgAction, self.goal_callback, False)
self._as.start()
self.ctrl_c = False
self.rate = rospy.Rate(10)

def publish_once_in_cmd_vel(self, cmd):
“”"
This is because publishing in topics sometimes fails teh first time you publish.
In continuos publishing systems there is no big deal but in systems that publish only
once it IS very important.
“”"
while not self.ctrl_c:
connections = self._pub_cmd_vel.get_num_connections()
if connections > 0:
self._pub_cmd_vel.publish(cmd)
rospy.loginfo(“Publish in cmd_vel…”)
break
else:
self.rate.sleep()

def up_drone(self):
while not i == 3:
self._pub_takeoff.publish(self._takeoff_msg)
rospy.loginfo(‘Taking off…’)
time.sleep(1)
i += 1
def down_drone(self):
while not i == 3:
self._pub_land.publish(self._land_msg)
rospy.loginfo(‘Landing…’)
time.sleep(1)
i += 1
def goal_callback(self, goal):
self._pub_takeoff = rospy.Publisher(’/drone/takeoff’, Empty, queue_size=1)
self._takeoff_msg = Empty()
self._pub_land = rospy.Publisher(’/drone/land’, Empty, queue_size=1)
self._land_msg = Empty()
word = goal.goal
if word == TAKEOFF:
self.up_drone()
rospy.loginfo(‘ca va monter’)

if word == LAND:
    self.down_drone()
    rospy.loginfo('ca va descendre')

if name == ‘main’:
rospy.init_node(‘move_drone_up_down’)
MoveSquareClass()
rospy.spin()

The command to reproduce is the following ; roslaunch action_custom_msg.launch

Don’t hesitate to tell me if you need something else

Ok I’ll have a look . I highly recomend you to use gits to share your wok, because it helps us have the exact same code, without having to edit it and create packages and everything

Here you have the file corrected. There were loads of things that were missing : https://gist.github.com/RDaneelOlivav/b0a040b32f8d2b8717117f0f45f94f2c

Please have a look at the examples, and also check your keyboard layout because it seems that it is using some code not compatible with python code normally.

Thank you for your answer! Indeed, I forgot some things on my code. But when I launch it, I still have the same error (but this time it’s “no module named msg” instead of “no module named action” :

I think it’s maybe a problem in my folder tree, I’ll try to find a solution.
image
If you have any idea of what the problem is, don’t hesitate to tell me.

Hi @quentin.roudier,

Please also check the following:

  • Have you run catkin_make again, after modifying your files?
  • Have you run source devel/setup.bash oN EVERY SHELL after running catkin_make?

If it still doesn’t work, then I suggest you look at the examples more closely and correct your code as necessary, as suggested by @duckfrost.

Hello Bayodesegun,

Thanks for your answer. I ran the source devel/setup.bash one every shell but I still have the same error…
I’ll try to find the error by myself but don’t hesitate to tell me if you have an idea.

Hello everyone,

So I finally gave up and made correct my quiz (with a painful 3.5, painful because I think my code was pretty similar) but, even when I launched the solution, I still have the same error, I used all the files of the solution and checked each folder name but it’s still the same…

Im going to the next lesson but if someone has an idea of what the could be the origin of the error, it would be interesting.

Hello @quentin.roudier,

I suggest you change the name of the Python file, actions_quiz.py. Your package (actions_quiz) and your Python script (actions_quiz.py) have the same name and this might cause some importing issues, because ROS might try to do the imports from the script instead of the package. Try to change the name of the script to, for instance, actions_quiz_code.py and let me know if it solves your issues.

Best,

Hello albertoezquerro,

Thank you for your answer and for your help. I changed the name of the script, I obviously modified my launch file but, one more time, I have the same error :


I launched the code of the solution by the way. I think it’s certainly a problem in my folder tree but of course I don’t find it :
image

@quentin.roudier,

Sorry for all the trouble. But don’t worry, it will pass. It’s just a learning stage.

The error is saying that it cannot find the msg directory, and that suggests that the messages have not been created perhaps because you have not done the setup required in CMakeLists.txt and package.xml…This directory is created automatically during catkin_make if the system finds the required information to create them.

I suggest that you:

  1. Go over the instructions in Unit 9- Understanding ROS Actions - Servers under the heading How to prepare CMakeLists.txt and package.xml files for custom action messages compilation and ensure you have modified the files accordingly. If you have done it before, please go over what you have done to ensure everything is correctly done.
  2. Run catkin_make and source devel/setup.bash again.

PS: If the setup is right, you should see some output on the terminal during catkin_make that indicates that some messages are being generated. Something like:

[  2%] Generating Python from MSG actions_quiz/CustomActionMsgGoal
[  5%] Generating Python from MSG actions_quiz/CustomActionMsgAction
[  8%] Generating Python from MSG actions_quiz/CustomActionMsgActionFeedback

Thank you for your help, I already checked about the CMakeLists.txt and the package.xml. At the beginning, I had the same thing than the solution except I had the std_msgs lines. I tried with the CMakeLists.txt and the package.xml of the solution but I still have this error.

I don’t have these lines btw :
[ 2%] Generating Python from MSG actions_quiz/CustomActionMsgGoal
[ 5%] Generating Python from MSG actions_quiz/CustomActionMsgAction
[ 8%] Generating Python from MSG actions_quiz/CustomActionMsgActionFeedback

Hi @quentin.roudier,

From the error you copied above, you can see that it’s still executing a file named actions_quiz.py. Make sure that you remove that file and all the references to it, and that you only have the actions_quiz_code.py file.

Also, remove the build and devel folders and compile everything again.

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

Best,

1 Like

Hi albertoezquerro,

Thank you for your answer! Indeed, I didn’t pay attention at that part of the error message. So I guess you find the origin of the problem. But the actions_quiz.py has already been removed from the folder as you can see :
image
Maybe the obsolet py code is more hidden than removed, I don’t know :thinking:

I still ran these lines btw:

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

But I have still the same error :

So, as I said before, maybe the code is not totally removed? I checked in the other files and I haven’t found any references to the old py code…

1 Like

Hi @quentin.roudier,

Hmm… that’s pretty strange. Have a look inside the src folder through the WebShell, using the ls command, to check that there isn’t any Python compiled file, which have the extension .pyc and they don’t show up on the IDE. If you find a file named actions_quiz.pyc, remove it.

That’s the only explanation I can think of right now.

Best,

2 Likes

Hi albertoezquerro,

Thank you very much for your answer, you solved the problem. Indeed, the actions_quiz.pyc wasn’t removed. Now the program is perfectly working. Thank you everyone for the time you dedicated on my problem!

2 Likes