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

Error when trying to run a python node built with the --symlink-install option

asked 2018-08-27 23:03:52 -0500

Marc Testier gravatar image

updated 2018-08-29 01:01:45 -0500

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>
edit retag flag offensive close merge delete

Comments

I just tried it with the example shown and colcon build --symlink-install. After sourcing install/setup.bash I was able to call client without a problem. Maybe check that you have the latest version of colcon (e.g. with colcon version-check).

Dirk Thomas gravatar image Dirk Thomas  ( 2018-08-28 09:55:31 -0500 )edit

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.

Marc Testier gravatar image Marc Testier  ( 2018-08-28 21:20:12 -0500 )edit

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>

Marc Testier gravatar image Marc Testier  ( 2018-08-29 01:04:22 -0500 )edit

1 Answer

Sort by » oldest newest most voted
1

answered 2018-08-28 01:11:58 -0500

Marc Testier gravatar image

updated 2018-08-28 03:18:25 -0500

Ok, I fixed it, the name of the folder needs to be the same as the name of the package... Don't know if we just can't have different names of if I need to change some configs somewhere but since I'm new to ROS2 + python, I'm just going to rename the folder (and it's the best practice anyway).

It probably worked before because of some cached files.

EDIT: Nevermind, it only temporary worked. I opened another terminal, sourced and the problem appeared again. I found that if I source the file in the install folder : install/opc_client/share/opc_client/package.bash then it works...

edit flag offensive delete link more

Comments

You might want to report this over at the issue tracker of one of the repositories in github.com/colcon. I'm not sure which one that should be though ..

Perhaps @Dirk Thomas can help.

gvdhoorn gravatar image gvdhoorn  ( 2018-08-28 03:20:05 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2018-08-27 23:03:52 -0500

Seen: 1,013 times

Last updated: Aug 29 '18