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

Revision history [back]

click to hide/show revision 1
initial version

you need to change the package_dir in setup.py from "src" to "scripts". And packages in setup.py should be "middle_abstraction", the directory that contains the python file.

## ! 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=['middle_abstraction'],#python pkg name
    package_dir={'': 'scripts'},
    requires=['std_msgs', 'rospy', 'message_filters', 'gps_common', 'sensor_msgs']
)

setup(**setup_args)

then create a __init__.py file in the directory middle_abstraction, Then you can import the python file like this

a.py

 import sys
 sys.path.append("..")
 import middle_abstraction.function_unit

you need to change the package_dir package_dir in setup.py setup.py from "src" "src" to "scripts". "scripts". And packages packages in setup.py setup.py should be "middle_abstraction", "middle_abstraction", the directory that contains the python file.

## ! 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=['middle_abstraction'],#python pkg name
    package_dir={'': 'scripts'},
    requires=['std_msgs', 'rospy', 'message_filters', 'gps_common', 'sensor_msgs']
)

setup(**setup_args)

then create a __init__.py file in in the directory middle_abstraction, and don't forget to uncomment the `catkiCMakeLists.txt file.*

Then you can import the python file like this

a.py

 import sys
 sys.path.append("..")
 import middle_abstraction.function_unit

you need to change the package_dir in setup.py from "src" to "scripts". And packages in setup.py should be "middle_abstraction", the directory that contains the python file.

## ! 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=['middle_abstraction'],#python pkg name
    package_dir={'': 'scripts'},
    requires=['std_msgs', 'rospy', 'message_filters', 'gps_common', 'sensor_msgs']
)

setup(**setup_args)

then create a __init__.py file in in the directory middle_abstraction, , and don't forget to uncomment the the catkin_python_setup() statement in CMakeLists.txt `catkiCMakeLists.txt file.*

Then after catkin_make, you can import the file like this

a.py

 import sys
 sys.path.append("..")
 import middle_abstraction.function_unit