0

I am trying to run a script using an interface created with tkinter. I have a button that executes a script which code is:

subprocess.call("python3 " + PATH_TO_SCRIPTS + "main.py 1 &", shell=True)

However, when this button is pressed I am getting the following error.

Traceback (most recent call last):
    File "/home/m//PycharmProjects/ROSAutonomousFlight/catkin_ws/src/ardrone_numeric_method_controller/scripts/main.py", line 17, in <module>
      from controller import *
    File "/home/m/PycharmProjects/ROSAutonomousFlight/catkin_ws/src/ardrone_numeric_method_controller/scripts/controller.py", line 5, in <module>
      import rospy

It says that the module rospy does not exist, but when I run import rospy using python or python3 it is imported successfully. What can I do to solve this issue? I am using Ubuntu.

7
  • 2
    Where does rospy.py exist? Is it there in your sys.path or PYTHONPATH ? Commented Jul 15, 2015 at 4:32
  • Can you show the structure in which rospy exists, compared to main.py ? Commented Jul 15, 2015 at 4:34
  • this is what I have in main.py from controller import *, and this import rospy is what I have in controller.py both py files are in the same directory. There is more code but here is where I am getting the error. Commented Jul 15, 2015 at 4:36
  • Could this be of any help : wiki.ros.org/rospy/Troubleshooting Commented Jul 15, 2015 at 4:42
  • @Imiguelvargasf To check your path, you can use import sys and then print sys.path Commented Jul 15, 2015 at 4:43

1 Answer 1

2

The comments to your question are mostly about Python, but I guess it is more of a ROS issue.

You don't have to set-up your PYTHONPATH manually to find rospy but you have to source the setup.bash of your catkin workspace (otherwise none of the ROS tools is found).

Usually this is done by adding something like

source ~/catkin_ws/devel/setup.bash

to .bashrc. This works fine for everything that is run in a terminal.

I don't know how you start your script but as it provides a graphical interface you probably just run it by double-clicking it in the file browser? If you indeed do so, the script is not run in a terminal and therefore can't find the ROS modules. Run the script from a terminal (in which the setup.bash has been sourced) and it should work.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.