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

rospy ImportError - cannot find custom module under src/ folder

asked 2016-01-07 04:13:41 -0500

K Chen gravatar image

Here are the steps to reproduce:

  1. create a new package under ~/catkin_ws/src:

    catkin_create_pkg foopy rospy
  2. create src/foopy folder and add in it

  3. create a under scripts/ folder:

#!/usr/bin/env python
# -*- coding: utf-8

import roslib; roslib.load_manifest('foopy')
import rospy

import sys
for f in sys.path:
    print f
Then chmod +x and execute it using: rosrun foopy It prints:

Which does not include module foopy of my src/foopy folder. So when I import anything created under src/foopy/, it will raise an ImportError.

How to solve this issue?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2016-01-07 04:20:24 -0500

gvdhoorn gravatar image

updated 2016-01-07 04:25:55 -0500

How to solve this issue?

Have you created a and uncommented the catkin_python_setup() line of your CMakeLists.txt?

See wiki/rospy_tutorials/Tutorials/Makefile - Installing scripts and exporting modules and Catkin 0.6.16 documentation » User Guide » Handling of

Edit: you also don't mention whether you've rebuilt your workspace before trying to execute your script. Catkin cannot generate the necessary setup.* files (that will setup your PYTHONPATH) if you don't.

Also: import roslib; roslib.load_manifest('foopy') is not necessary anymore in Hydro+.

edit flag offensive delete link more


Many thanks for your reply! Problem resolved!

K Chen gravatar image K Chen  ( 2016-01-07 11:16:59 -0500 )edit

But it's weird when I am printing out the sys.path, it does not include src path still, but when I import some file under 'src/foopy' using from foopy import foopkg it is working. How did python find

K Chen gravatar image K Chen  ( 2016-01-07 11:27:13 -0500 )edit

This totally solved my problem, after already having struggled for many hours. I had done everything EXCEPT uncomment catkin_python_setup() in CMakeLists.txt. After doing that, it worked perfectly.

sheaffej gravatar image sheaffej  ( 2018-01-21 13:41:31 -0500 )edit

Question Tools

1 follower


Asked: 2016-01-07 04:13:41 -0500

Seen: 3,020 times

Last updated: Jan 07 '16