Can't compile cartographer_slam package in ROS2 Navigation Unit 2

I get this error when I try to compile the cartographer_slam package

user:~/ros2_ws$ colcon build --packages-select cartographer_slam
Traceback (most recent call last):
File “”, line 1, in
File “/usr/lib/python3.10/distutils/core.py”, line 215, in run_setup
exec(f.read(), g)
File “”, line 4
(os.path.join(‘share’, package_name, ‘launch’), glob(‘launch/*.launch.py’)),
IndentationError: unexpected indent
[2.708s] ERROR:colcon.colcon_core.package_identification:Exception in package identification extension ‘python_setup_py’ in ‘src/cartographer_slam’: Command ‘[’/usr/bin/python3’, ‘-c’, ‘import sys;from contextlib import suppress;exec(“with suppress(ImportError): from setuptools.extern.packaging.specifiers import SpecifierSet”);exec(“with suppress(ImportError): from packaging.specifiers import SpecifierSet”);from distutils.core import run_setup;dist = run_setup( 'setup.py', script_args=('–dry-run',),stop_after='config');skip_keys = ('cmdclass', 'distclass', 'ext_modules', 'metadata');data = { key: value for key, value in dist.dict.items() if ( not key.startswith('_') and not callable(value) and key not in skip_keys and key not in dist.display_option_names )};data['metadata'] = { k: v for k, v in dist.metadata.dict.items() if k not in ('license_files', 'provides_extras')};sys.stdout.buffer.write(repr(data).encode('utf-8'))’]’ returned non-zero exit status 1.
Traceback (most recent call last):
File “/usr/lib/python3/dist-packages/colcon_core/package_identification/init.py”, line 142, in _identify
retval = extension.identify(_reused_descriptor_instance)
File “/usr/lib/python3/dist-packages/colcon_python_setup_py/package_identification/python_setup_py.py”, line 48, in identify
config = get_setup_information(setup_py)
File “/usr/lib/python3/dist-packages/colcon_python_setup_py/package_identification/python_setup_py.py”, line 241, in get_setup_information
_setup_information_cache[hashable_env] = _get_setup_information(
File “/usr/lib/python3/dist-packages/colcon_python_setup_py/package_identification/python_setup_py.py”, line 288, in get_setup_information
result = subprocess.run(
File “/usr/lib/python3.10/subprocess.py”, line 526, in run
raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command ‘[’/usr/bin/python3’, ‘-c’, 'import sys;from contextlib import suppress;exec(“with suppress(ImportError): from setuptools.extern.packaging.specifiers import SpecifierSet”);exec(“with suppress(ImportError): from packaging.specifiers import SpecifierSet”);from distutils.core import run_setup;dist = run_setup( 'setup.py', script_args=('–dry-run',), stop_after='config');skip_keys = ('cmdclass', 'distclass', 'ext_modules', 'metadata');data = { key: value for key, value in dist.dict.items() if ( not key.startswith('
') and not callable(value) and key not in skip_keys and key not in dist.display_option_names )};data['metadata'] = { k: v for k, v in dist.metadata.dict.items() if k not in ('license_files', 'provides_extras')};sys.stdout.buffer.write(repr(data).encode('utf-8'))‘]’ returned non-zero exit status 1.

[2.738s] WARNING:colcon.colcon_core.package_selection:ignoring unknown package ‘cartographer_slam’ in --packages-select

Summary: 0 packages finished [2.14s]

The error output suggests a syntax error in setup.py.

Double check that the addition of os.path.join... is correct.

This is my code, and it still doesn’t work:

Well, that file is incomplete.

Please go through the instructions and check the structure of the entire file. You should add those two lines to the already existing setup.py, not replace the entire file with that.

This is what I added to my code:

from setuptools import setup
import os
from glob import glob

package_name = ‘nav2_project’

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’]),
(os.path.join(‘share’, package_name, ‘launch’), glob(‘launch/launch.py’)),
(os.path.join(‘share’, package_name, ‘launch’), glob('launch/
.launch.py’)),
(os.path.join(‘share’, package_name, ‘config’), glob(‘config/')),
(os.path.join(‘share’, package_name, ‘config’), glob('config/
.yaml’)),
(os.path.join(‘share’, package_name, ‘config’), glob(‘config/.pgm’)),
(os.path.join(‘share’, package_name, ‘config’), glob('config/
.rviz’)),
(os.path.join(‘share’, package_name, ‘config’), glob(‘config/.xml’)),
(os.path.join(‘share’, package_name, ‘config’), glob('config/
.lua’)),
],
install_requires=[‘setuptools’],
zip_safe=True,
maintainer=‘user’,
maintainer_email=‘user@todo.todo’,
description=‘TODO: Package description’,
license=‘TODO: License declaration’,
tests_require=[‘pytest’],
entry_points={
‘console_scripts’: [
‘go_to_pose = nav2_project.go_to_pose:main’,
‘spot_recorder = nav2_project.spot_recorder:main’,
],
},
)

I’m getting this error when I want to use colcon build --packages-select cartographer_slam:
.645s] WARNING:colcon.colcon_core.package_selection:ignoring unknown package’cartographer_slam’ in --packages-select

Summary: 0 packages finished [2.02s]
user:~/ros2_ws/src/cartographer_slam$ cd ~/ros2_wsuser:~/ros2_ws$ colcon build --packages-select cartographer_slam
[2.929s] WARNING:colcon.colcon_core.package_selection:ignoring unknown package’cartographer_slam’ in --packages-select

Summary: 0 packages finished [2.26s]

If your package is configured corretly, then it should be able to find it and compile it just with colcon build

I retried Unit 1 and Unit 2 atleast 3 times.
I still get the error message

I can see a build/ folder inside src/, so a compilation was done in the incorrect place and might be contributing to the error.

Compilation should always be done in ~/ros2_ws.

Also, double check that the package name in setup.py is set correctly.

Hi @kg_robotics
I can see you have several things wrong:

  1. I can see you copied the setup.py file from another project without modifying it properly. You cannot do that because then your system will have inconsistencies. You should use the setup.py file that automatically generated the package creator and then modify according to your needs

For instance, your setup.py says

package_name = 'nav2_project'

That is not correct. It should say the name of your package.

Also says:

  entry_points={
       'console_scripts': [
           'go_to_pose = nav2_project.go_to_pose:main',
           'spot_recorder = nav2_project.spot_recorder:main',
       ],

That is also not correct, because you don’t have entry points in your cartographer_slam package.

And so other things are wrong.

So please, create again the package and follow the modification instructions of the course

  1. You have directories named build, install and log within the directory of the cartographer_slam package. This suggests that you tried to compile within the directory /home/user/ros2_ws/src/cartographer_slam.

YOU CANNOT COMPILE OUTSIDE OF THE DIRECTORY /home/user/ros2_ws !!

That maybe the main reason why you could not compile later when you had your files correctly and then you entered in a spiral of non-understanding what to do, which led you to copy the wrong setup.py.

You need to delete those directories inside the cartographer_slam package. But my recommendation is that you delete the whole package and start again following the indications of the course and taking into consideration my comments above.

All those errors suggest that you do not know ROS2 Basics. Hence you should not attempt this course without taking first the whole ROS 2 Basics (Python) course.

Let me know if you understood the problem and are clear to proceed

Hi rtellez,

Sorry, sometimes I accidentally post in my personal account xxpreseaxx. I’m using my school account kg_robotics.
I followed your feedback.
I believe I was able to get a step further.
Now I get the error:
"Starting >>> cartographer_slam
— stderr: cartographer_slam
error: package directory ‘cartographer_slam’ does not exist

Failed <<< cartographer_slam [1.64s, exited with code 1]

Summary: 0 packages finished [3.89s]
1 package failed: cartographer_slam
1 package had stderr output: cartographer_slam"

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.