ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

rosrun and finding python files in other packages using catkin

asked 2013-03-04 09:57:53 -0600

TommyP gravatar image

updated 2014-01-28 17:15:30 -0600

ngrennan gravatar image

I asked a similar question and got it to work with global scripts but not with rosrun.

So now I wonder how to do the following:

In package A i have

A/src/mp.py

In package B I have a file

A/src/test.py

which has the line:

from mp import *

Now when I do "rosrun A test.py" mp.py is not found. What is the correct way to solve this. Exactly what should I write in setup.py and in CMakeFile.txt?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2013-03-04 10:27:15 -0600

KruseT gravatar image

In setup.py of package A, you need to export the module. The cleanest way is to use a python package. So you should put mp.py in a python package, like

A/
A/setup.py
A/src/
A/src/mp/
A/src/mp/__init__.py
A/src/mp/mp.py

Then in setup.py declare the package mp, and enable the line catkin_python_setup() in A's CMakeLists.txt. Then run catkin_make. This will generate package relay files, in devel/lib/python2.7/dist-packages/A. Then source devel/setup.sh. This will change your PYTHONPATH to include the package relay files.

See:

http://ros.org/doc/groovy/api/catkin/html/user_guide/setup_dot_py.html

http://ros.org/wiki/rospy_tutorials/Tutorials/Makefile

edit flag offensive delete link more

Comments

OK. So the thing that was possible with rosbuild is no longer possible. That should be documented somewhere since I have wasted some time trying to figure out how to get it to work as with rosbuild. I need to read up on Python packages I see.

TommyP gravatar image TommyP  ( 2013-03-04 10:45:53 -0600 )edit

Got it to work. Thanks for the good answer.

TommyP gravatar image TommyP  ( 2013-03-04 11:05:58 -0600 )edit

Is the package fund before system packages? I have a package called tst but the import seems to select "/usr/share/doc/python-libxml2/examples/tst.py". I solved my problem with "import tst.tst" but it was very confusing.

TommyP gravatar image TommyP  ( 2013-03-04 23:18:17 -0600 )edit

That's how python does it, and that's why it is best to always use packages, and to always import giving the full name with the package.

KruseT gravatar image KruseT  ( 2013-03-05 02:30:17 -0600 )edit

Question Tools

Stats

Asked: 2013-03-04 09:57:53 -0600

Seen: 301 times

Last updated: Mar 04 '13