ROS2 Python relative import of my scritps
Hi guys, I have a project on Raspberry pi 3, a compiled ROS2 foxy from source, install Kivy and everything if fine. But now I'm trying to port my UI from ROS1 to ROS2 and I can't figure out how to do relative imports like from utils. See to code.
Package(ROS2) hierarchy:
control_panel_ui
├── control_panel_ui
│ ├── graphical_interface.py
│ ├── __init__.py
│ ├── listeners
│ │ ├── __init__.py
│ │ └── start_listeners.py
│ ├── media
│ │ └── image.png
│ └── utils
│ ├── dict_services.py
│ ├── get_rpc.py
│ ├── __init__.py
│ ├── states.py
│ └── vehicle_state.py
├── package.xml
├── setup.cfg
├── setup.py
├── ...
And the code. Kivy is imported fine but my code such as utils, listeners etc. doesn't.
#kivy.require('1.7.2')
from kivy.app import App
...
from kivy.clock import Clock
from .utils.vehicle_state import VehicleState
from .utils.dict_services import dict_serv
from .utils.get_rpc import get_rpc_function
...
After the colcon build [package].py is moved to the install directory but those utils doesn't and then it it says cannot find package.
edited: Maybe the thing is I don't know how to configure setup.py/.cfg. Maybe a link or an example would be great. I was not able to find anything uselful.
added setup.py/.cfg
from setuptools import setup
package_name = 'control_panel_ui'
setup(
name=package_name,
version='0.0.0',
packages=[package_name],
data_files=[
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
('share/' + package_name, ['package.xml'])
],
install_requires=['setuptools'],
zip_safe=True,
maintainer='pi',
maintainer_email='michal@michal.com',
description='TODO: Package description',
license='TODO: License declaration',
tests_require=['pytest'],
entry_points={
'console_scripts': [
'control_panel_ui = control_panel_ui.graphical_interface:graphical_interface'
],
},
)
cfg
[develop]
script-dir=$base/lib/control_panel_ui
[install]
install-scripts=$base/lib/control_panel_ui
You need to share the content of your
setup.py
/setup.cfg
files.