0
$\begingroup$

I'm trying to build a simple empty Python package on ROS Humble. I created the package using:

ros2 pkg create test_py --build-type ament_python

Then, I built it with:

colcon build

The build fails. Any advice in what should I do?

Build reports the following errors:

Starting >>> test_py 
--- stderr: test_py                   
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/colcon_core/executor/__init__.py", line 91, in __call__
    rc = await self.task(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/colcon_core/task/__init__.py", line 93, in __call__
    return await task_method(*args, **kwargs)
  File "/usr/lib/python3/dist-packages/colcon_ros/task/ament_python/build.py", line 105, in build
    return await extension.build(additional_hooks=additional_hooks)
  File "/usr/lib/python3/dist-packages/colcon_core/task/python/build.py", line 81, in build
    available_commands = await self._get_available_commands(
  File "/usr/lib/python3/dist-packages/colcon_core/task/python/build.py", line 171, in _get_available_commands
    output = await check_output(
  File "/usr/lib/python3/dist-packages/colcon_core/subprocess.py", line 128, in check_output
    assert not rc, f'Expected {args} to pass: {stderr_data}'
AssertionError: Expected ['/usr/bin/python3', 'setup.py', '--help-commands'] to pass: Traceback (most recent call last):
  File "/home/matheus/dev/ros2_ws/klrb_ws/src/harvest_detection/test_py/setup.py", line 5, in <module>
    setup(
  File "/home/matheus/.local/lib/python3.10/site-packages/setuptools/__init__.py", line 153, in setup
    return distutils.core.setup(**attrs)
  File "/usr/lib/python3.10/distutils/core.py", line 134, in setup
    ok = dist.parse_command_line()
  File "/usr/lib/python3.10/distutils/dist.py", line 480, in parse_command_line
    if self.handle_display_options(option_order):
  File "/home/matheus/.local/lib/python3.10/site-packages/setuptools/dist.py", line 1120, in handle_display_options
    return _Distribution.handle_display_options(self, option_order)
  File "/usr/lib/python3.10/distutils/dist.py", line 683, in handle_display_options
    self.print_commands()
  File "/home/matheus/.local/lib/python3.10/site-packages/setuptools/dist.py", line 896, in print_commands
    cmdclass = ep.resolve()
  File "/home/matheus/.local/lib/python3.10/site-packages/pkg_resources/__init__.py", line 2456, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/home/matheus/.local/lib/python3.10/site-packages/setuptools/command/build_ext.py", line 19, in <module>
    __import__('Cython.Compiler.Main')
  File "/home/matheus/.local/lib/python3.10/site-packages/Cython/Compiler/Main.py", line 28, in <module>
    from .Scanning import PyrexScanner, FileSourceDescriptor
  File "Cython/Compiler/Scanning.py", line 1, in init Cython.Compiler.Scanning
  File "/home/matheus/.local/lib/python3.10/site-packages/Cython/Plex/__init__.py", line 36, in <module>
    from .Lexicons import Lexicon, State
  File "/home/matheus/.local/lib/python3.10/site-packages/Cython/Plex/Lexicons.py", line 14, in <module>
    from . import DFA
  File "Cython/Plex/DFA.py", line 1, in init Cython.Plex.DFA
AttributeError: module 'Cython.Plex.Actions' has no attribute 'Method'

---
Failed   <<< test_py [0.36s, exited with code 1]

Summary: 0 packages finished [0.53s]
  1 package failed: test_py
  1 package had stderr output: test_py
Expected ['/usr/bin/python3', 'setup.py', '--help-commands'] to pass: Traceback (most recent call last):
  File "/home/matheus/dev/ros2_ws/klrb_ws/src/harvest_detection/test_py/setup.py", line 5, in <module>
    setup(
  File "/home/matheus/.local/lib/python3.10/site-packages/setuptools/__init__.py", line 153, in setup
    return distutils.core.setup(**attrs)
  File "/usr/lib/python3.10/distutils/core.py", line 134, in setup
    ok = dist.parse_command_line()
  File "/usr/lib/python3.10/distutils/dist.py", line 480, in parse_command_line
    if self.handle_display_options(option_order):
  File "/home/matheus/.local/lib/python3.10/site-packages/setuptools/dist.py", line 1120, in handle_display_options
    return _Distribution.handle_display_options(self, option_order)
  File "/usr/lib/python3.10/distutils/dist.py", line 683, in handle_display_options
    self.print_commands()
  File "/home/matheus/.local/lib/python3.10/site-packages/setuptools/dist.py", line 896, in print_commands
    cmdclass = ep.resolve()
  File "/home/matheus/.local/lib/python3.10/site-packages/pkg_resources/__init__.py", line 2456, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "/home/matheus/.local/lib/python3.10/site-packages/setuptools/command/build_ext.py", line 19, in <module>
    __import__('Cython.Compiler.Main')
  File "/home/matheus/.local/lib/python3.10/site-packages/Cython/Compiler/Main.py", line 28, in <module>
    from .Scanning import PyrexScanner, FileSourceDescriptor
  File "Cython/Compiler/Scanning.py", line 1, in init Cython.Compiler.Scanning
  File "/home/matheus/.local/lib/python3.10/site-packages/Cython/Plex/__init__.py", line 36, in <module>
    from .Lexicons import Lexicon, State
  File "/home/matheus/.local/lib/python3.10/site-packages/Cython/Plex/Lexicons.py", line 14, in <module>
    from . import DFA
  File "Cython/Plex/DFA.py", line 1, in init Cython.Plex.DFA
AttributeError: module 'Cython.Plex.Actions' has no attribute 'Method'
$\endgroup$

1 Answer 1

0
$\begingroup$

The failure is AssertionError: Expected ['/usr/bin/python3', 'setup.py', '--help-commands'] to pass which is just a sanity check that ROS does before building a python package to make sure that python is correctly setup.

The traceback shows that you appear to have corrupted packages in your PYTHONPATH In particular your Cython package appears be erroring when python is looking for command entry points.

You will need to resolve issues in that package before you can effectively use python. You can either remove that package or resolve it's import errors, potentially by reinstalling it.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.