Python import: rosrun works well but roslaunch reports error
Hi, I'm writing some rospy nodes recently and some import errors ocur when I utilize roslaunch to start my node.
a.py
1 import sys
2 sys.path.append("..")
3 from middle_abstraction.function_unit import FunctionUnit
ImportError: No module named middle_abstraction.function_unit
The file is organized as following
package
scripts
basic_support
a.py
middle_abstraction
function_unit.py
When I cd
to basic_support and run python a.py
, everthing is working well as well as when I utilize rosrun pkg a.py
. But when I utilize roslaunch, this error ocurs.
I have written one setup.py file in my pkg folder:
## ! DO NOT MANUALLY INVOKE THIS setup.py, USE CATKIN INSTEAD
from distutils.core import setup
from catkin_pkg.python_setup import generate_distutils_setup
# fetch values from package.xml
setup_args = generate_distutils_setup(
packages=['multi_robot_patrol'],#my pkg name
package_dir={'': 'src'},
requires=['std_msgs', 'rospy', 'message_filters', 'gps_common', 'sensor_msgs']
)
setup(**setup_args)
I'm really confused that rosrun works pretty well but roslaunch reports import error. I'd appreciate it if anyone can help me.
In your setup.py you list 'src' as the package_dir but I don't see any 'src' directory in your package directories.