Reference: Installing Python scripts and modules
├── my_pkg
│ ├── setup.py
│ ├── scripts
│ │ └── executable_script
└── src
└── my_pkg
├── __init__.py
└── my_module.py
- There needs to be a
setup.py
. - Executable scripts should go under
my_pkg/scripts
ormy_pkg/nodes
. - Importable modules should be placed under
src/my_pkg
. - There needs to be an
__init__.py
undersrc/my_pkg
.
## ! 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=['my_pkg'],
package_dir={'': 'src'},
requires=['std_msgs', 'rospy', 'rosbag', 'tf']
)
setup(**setup_args)
Never run python setup.py install
. Only use catkin to install the module.
Run
catkin_make
Then
source catkin_ws/devel/setup.bash
Now you should be able to import the code in my_pkg
from any other location on your computer.