Error when trying to run a python node built with the --symlink-install option
Hello,
I'm using ROS2 Bouncy, built from source on Ubuntu 18.04 and I'm trying to build a python node using colcon build --symlink-install
but when running the node, it gives me an error ModuleNotFoundError: No module named 'src.client'
.
When I build without the --symlink-install
, it works but then I have to build every time I modify the python file...
I'm probably doing something wrong because yesterday, it worked... I could build with the --symlink-install
option and could modify the python file without having to build again. I cleaned the install and build folder and now it doesn't work.
The code can be found here : https://github.com/MarcTestier/kone_o...
There is 3 packages : the server, the client and an interface package with just 2 srv files.
You can run the full thing by running : ros2 run kone_open_opc_server_simu kone_simu
then ros2 run kone_open_opc_client kone_client
Here is the folder structure :
├── client
│ ├── package.xml
│ ├── resource
│ │ └── opc_client
│ ├── setup.cfg
│ ├── setup.py
│ └── src
│ ├── client.py
│ └── __init__.py
And the setup.py :
from setuptools import find_packages
from setuptools import setup
package_name = 'opc_client'
setup(
name=package_name,
version='0.5.1',
packages=find_packages(),
data_files=[
('share/ament_index/resource_index/packages',
['resource/' + package_name]),
('share/' + package_name, ['package.xml']),
],
install_requires=['setuptools'],
zip_safe=True,
author='Marc-Antoine Testier',
author_email='marc.testier@gmail.com',
maintainer='Marc-Antoine Testier',
maintainer_email='marc.testier@gmail.com',
keywords=['ROS'],
classifiers=[
'Intended Audience :: Developers',
'License :: OSI Approved :: Apache Software License',
'Programming Language :: Python',
'Topic :: Software Development',
],
description=(
'TODO'
),
license='Apache License, Version 2.0',
entry_points={
'console_scripts': [
'client = src.client:main',
],
},
)
The python file client.py :
#!/usr/bin/env python
import rclpy
from rclpy.node import Node
class OpcClient(Node):
def __init__(self):
super().__init__('opc_client')
# AGV Identifier
self.simu = 1
# Simulation bool
self.agvID = "AGV1"
def main(args=None):
rclpy.init(args=args)
node = OpcClient()
rclpy.spin(node)
# Destroy the node explicitly
# (optional - Done automatically when node is garbage collected)
node.destroy_node()
rclpy.shutdown()
if __name__ == '__main__':
main()
The package.xml just in case :
<?xml version="1.0"?>
<package format="2">
<name>opc_client</name>
<version>0.0.0</version>
<description>OPC client</description>
<maintainer email="marc.testier@gmail.com">Marc-Antoine Testier</maintainer>
<author email="marc.testier@gmail.com">Marc-Antoine Testier</author>
<license>Apache License 2.0</license>
<exec_depend>rclpy</exec_depend>
<exec_depend>std_msgs</exec_depend>
<test_depend>ament_copyright</test_depend>
<test_depend>ament_pep257</test_depend>
<test_depend>ament_pep8</test_depend>
<test_depend>ament_pyflakes</test_depend>
<test_depend>rclpy</test_depend>
<test_depend>std_msgs</test_depend>
<export>
<build_type>ament_python</build_type>
</export>
</package>
I just tried it with the example shown and
colcon build --symlink-install
. After sourcinginstall/setup.bash
I was able to callclient
without a problem. Maybe check that you have the latest version ofcolcon
(e.g. withcolcon version-check
).Colcon is up-to date, but since you don't have the problem, it's probably my fault, might have forgotten a step during the installation. What bugs me is that I can still directly source the package in the install folder... I'll try on another machine with a clean installation and update the post.
Updated the post with a github link to the code. I have the same problem when using it with another machine with ros2 bouncy from the debian packages. The server package which has a similar structure works but not the client one... still have to source the package.bash in install/<pkg>/share/<pkg>