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

pylint & pychecker

asked 2012-07-03 00:22:57 -0600

narcispr gravatar image

updated 2014-01-28 17:12:53 -0600

ngrennan gravatar image

Have you tried to use pylint or pychecker to improve/check your python code? I've tried with pylint but it can't import rospy and srv or msg packages:

No config file found, using default configuration
F: 6: Unable to import 'rospy'
F: 8: Unable to import 'my_package.srv'
F: 9: Unable to import 'my_package.msg'
F: 10: Unable to import 'std_srvs.srv'
F: 11: Unable to import 'std_msgs.msg'
...

With PyChecker I've a similar problem:

Processing module my_node (my_node.py)...
ImportError: No module named srv

Warnings...

my_node:1: NOT PROCESSED UNABLE TO IMPORT

Any idea? I found this ticket related with this topic, but it was not very useful for me. Thank you!

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2012-07-03 01:08:52 -0600

KruseT gravatar image

updated 2012-07-04 23:54:57 -0600

It should be sufficient to have your ros environment set up. Meaning if you create your own ros package, make sure it is on the ROS_PACKAGE_PATH.

In your case the python file that has

import rospy

need to to have before that

import roslib
roslib.load_manifest('...')

with .. being either rospy or your package, but for the latter your package also needs to declare rospy in it's manifest.xml.

pychecker seems to be unable to check scripts that do not end with .py. The solution is to remove most of the code from such files like "my_node" and put the code inside the src folder. Then my_node can import the module from src, and pychecker can check the code in src.

EDIT: This should work in fuerte, and without roslib.load_manifest. In electric and earlier, load_manifest is required for pychecker. pylint ignores that, so pylint cannot find libraries in electric and before.

edit flag offensive delete link more

Comments

My node starts with: import roslib roslib.load_manifest('my_package') import rospy and the manisfest contains <depend package="rospy"/> but I've the problem previously mentioned.

narcispr gravatar image narcispr  ( 2012-07-03 01:14:26 -0600 )edit
1

Just a note: in Fuerte, roslib.load_manifest should not be required anymore and there is a pretty good chance that pychecker will work.

Lorenz gravatar image Lorenz  ( 2012-07-03 01:55:15 -0600 )edit

pylint --version No config file found, using default configuration pylint 0.23.0, astng 0.21.1, common 0.55.2 Python 2.7.2+ (default, Oct 4 2011, 20:03:08) [GCC 4.6.1] I'm using Ubuntu 11.10 & ROS Electric

narcispr gravatar image narcispr  ( 2012-07-03 05:35:40 -0600 )edit

$ pylint safety_g500.py | grep 'F:' No config file found, using default configuration F: 6: Unable to import 'rospy' F: 8: Unable to import 'safety_g500.srv' F: 9: Unable to import 'safety_g500.msg' F: 10: Unable to import 'std_srvs.srv' ...

narcispr gravatar image narcispr  ( 2012-07-03 05:36:33 -0600 )edit
1

ok, in electric, it is still required to run load_manifest. pylint however ignores load_manifest, so it will never be able to find rospy, unless you manually put it onto your PYTHONPATH before manually.

KruseT gravatar image KruseT  ( 2012-07-03 06:11:44 -0600 )edit

However pychecker should work, as long as you put your code into files named xyz.py. You can also name your nodes like that, to start with.

KruseT gravatar image KruseT  ( 2012-07-03 06:14:27 -0600 )edit

Question Tools

Stats

Asked: 2012-07-03 00:22:57 -0600

Seen: 2,326 times

Last updated: Jul 04 '12