Rosanswers logo

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 init.py in it

  3. create a main.py 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 main.py

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?

Originally posted by K Chen on ROS Answers with karma: 391 on 2016-01-07

Post score: 1


1 Answer 1


Rosanswers logo

How to solve this issue?

Have you created a setup.py 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 setup.py.

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+.

Originally posted by gvdhoorn with karma: 86574 on 2016-01-07

This answer was ACCEPTED on the original site

Post score: 2

Original comments

Comment by K Chen on 2016-01-07:
Many thanks for your reply! Problem resolved!

Comment by K Chen on 2016-01-07:
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 foopkg.py?

Comment by sheaffej on 2018-01-21:
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.


Your Answer

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