Reputation: 1
I am working on a ROS2 project and encountering an issue where my node cannot import modules from the configs package. Below is a detailed description of the problem, including the structure of my project, the error message, and steps I've already taken to troubleshoot.
test_ws/
├── src/
│ └── test_package/
│ ├── configs/
│ │ ├── __init__.py
│ │ └── global_settings.py
│ ├── test_package/
│ │ ├── __init__.py
│ │ ├── gps_path_planning_node.py
│ │ └── scripts/
│ │ ├── __init__.py
│ │ └── utils.py
│ ├── package.xml
│ ├── setup.cfg
│ └── setup.py
When I run the node using ros2 launch test_package simulation_launch.py
, I encounter the following error:
[gps_path_planning_node-5] Traceback (most recent call last):
[gps_path_planning_node-5] File "/home/hiber/Desktop/test_ws/install/test_package/lib/test_package/gps_path_planning_node", line 33, in <module>
[gps_path_planning_node-5] sys.exit(load_entry_point('test-package==0.0.0', 'console_scripts', 'gps_path_planning_node')())
...
[gps_path_planning_node-5] ModuleNotFoundError: No module named 'configs'
Code Snippet (gps_path_planning_node.py):
from rclpy.node import Node
import rclpy
from configs import global_settings
from test_package.scripts.utils import *
class GPSPathPlanningNode(Node):
def __init__(self):
super().__init__('gps_path_planning_node')
self.max_speed = EGO_VEHICLE_MAX_SPEED
self._logger.info('Successfully launched!')
def main(args=None):
rclpy.init(args=args)
node = GPSPathPlanningNode()
rclpy.spin(node)
node.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
The contents of setup.py are as follows:
import os
from setuptools import setup
PACKAGE_NAME = 'test_package'
def generate_data_files(share_path, data_files_path):
data_files_temp = []
for path, _, files in os.walk(data_files_path):
data_file = (
os.path.dirname(os.path.dirname(share_path)) + '/' + path, [
os.path.join(path, file) for file in files if not file.startswith('.')
]
)
data_files_temp.append(data_file)
return data_files_temp
data_files = []
data_files.append(('share/ament_index/resource_index/packages', ['resource/' + PACKAGE_NAME]))
data_files.append(('share/' + PACKAGE_NAME, ['package.xml']))
data_files += generate_data_files('share/' + PACKAGE_NAME + '/configs/', 'configs/')
data_files += generate_data_files('share/' + PACKAGE_NAME + '/launch/', 'launch/')
data_files += generate_data_files('share/' + PACKAGE_NAME + '/resource/', 'resource/')
setup(
name=PACKAGE_NAME,
version='0.0.0',
packages=[PACKAGE_NAME],
data_files=data_files,
install_requires=['setuptools'],
zip_safe=True,
maintainer='hiber',
maintainer_email='...',
description='TODO: Package description',
license='TODO: License declaration',
tests_require=['pytest'],
entry_points={
'console_scripts': [
# 'ackermann_keyboard_teleop_node = test_package.ackermann_keyboard_teleop_node:main',
'gps_path_planning_node = test_package.gps_path_planning_node:main',
'projection_weight_matrices_node = test_package.projection_weight_matrices_node:main',
'surround_view_node = test_package.surround_view_node:main',
],
},
)
Environment Details:
Request for Help: I would appreciate any guidance on resolving this issue. Specifically:
Thank you!
Steps Taken So Far:
global_settings.py
to the same directory as gps_path_planning_node.py
and updated the import statement to from test_package.global_settings import *
. However, other modules from other folders are not found, such as utils.py
from scripts/
setup.py
includes all necessary packages (test_package and sub-packages like scripts).colcon clean
followed by colcon build --symlink-install
and sourced the workspace.python3 -c "from test_package.global_settings import *; print('Import successful')"
works without errors.install/test_package/lib/python3.10/site-packages/test_package/
should contain the other modules (the same configs/
with global_settings.py
and scripts/
with utils.py
). Is this really the case?__init__.py
file is in all directories.Despite the first four steps, the error continues to occur when running the node via ROS2.
Upvotes: 0
Views: 17