Rosanswers logo

ROS2 Foxy (on Ubuntu 20.04LTS Desktop)

Problem: urdf directory in package not being copied to the install folder
Error Msg:

InvalidLaunchFileError: Caught exception when trying to load file of format [py]: [Errno 2] No such file or directory: '/home/ubuntu/handsonros2/install/rviz2_basics/share/rviz2_basics/urdf/gopigoMinimal.urdf'

Package Tree: ~/handsonros2/src/chap3rviz2_basics/

├── CMakeLists.txt
├── launch
│   ├── ros1_gopigoMinimal_rviz.launch.donotuse
│   ├── ros1_gopigoMinimal_rviz_simple.launch.donotuse
│   └── ros2_gpgMin_rviz2_simple.launch.py
├── package.xml
├── README.md
├── ros1CMakeLists.txt
├── ros1package.xml
├── ros2CMakeLists.txt
├── ros2package.xml
├── rviz
│   ├── default.rviz
│   ├── gopigoMinimal.rviz
│   └── gpgMin.rviz2.rviz
├── setup.py
└── urdf
    ├── gopigoMinimal.urdf
    └── keith_gpg.urdf


import os
from glob import glob
from setuptools import setup
from setuptools import find_packages

package_name = 'rviz2_basics'

            ['resource/' + package_name]),
        ('share/' + package_name, ['package.xml']),
        (os.path.join('share', package_name), glob('launch/*.py)),
        (os.path.join('share', package_name), glob('urdf/*'))
    maintainer_email='[email protected]',
    description='ROS2 Version of Hands-On ROS - Chap4 RVIZ Basics',
    license='Apache License 2.0',
    # entry_points={
    #     'console_scripts': [
    #     ],


<?xml version="1.0"?>
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
<package format="3">
  <description>ROS2 Version of Hands-On ROS - Chap4 RVIZ Basics"</description>
  <maintainer email="[email protected]">slowrunner</maintainer>
  <license>Apache License 2.0</license>





Originally posted by RobotDreams on ROS Answers with karma: 327 on 2021-06-29

Post score: 1


2 Answers 2


Rosanswers logo

Make a modification in your launch file. Your other files are fine. Your setup.py will result the urdf files to be copied and not the directory like this: /home/ubuntu/handsonros2/install/rviz2_basics/share/rviz2_basics/gopigoMinimal.urdf
You can confirm if the file exists on this path by cd'ing into it.

If you'd like the syntax for reference, you can refer to this package.

Originally posted by trunc8 with karma: 156 on 2021-06-29

This answer was NOT ACCEPTED on the original site

Post score: 2

Original comments

Comment by RobotDreams on 2021-06-29:
That (urdf-tutorial) was what led me to add the setup.py in the first place. I originally created the package as a cmake which didn't include a setup.py or setup.cfg.

I deleted the build and install directories, and rebuilt - share/rviz2_basics/launch gets created with the launch files, but for some reason the urdf folder does not get created, (nor is the gopigoMinimal.urdf copied anywhere - did not get copied to share/rviz2_basics )

I added a setup.cfg file and tried again, no cigars - still launch folder but no urdf folder no urdf file.

I think I might see the problem - in CMakeLists.txt the install for the launch folder instructions exist, but not the urdf folder. I'll try adding that and see what happens.

Comment by trunc8 on 2021-06-29:
Yeah! CMakeLists and setup.py shouldn't be existing together. I missed them in your directory structure entirely! Your obervations in the other answer are correct. Cheers!


Rosanswers logo

Looks like setup.py was a red herring. I initially created the package with:

ros2 pkg create rviz2_basics

which created package.xml and CMakeLists.txt.

Then added dependencies to package.xml


Added launch files installation in the CMakeLists.txt

# (Always add before ament_package() line)
# Install launch files
but did not at that time understand I also needed:
# Install urdf files

and started following the urdf-tutorial which creates a setup.py to satisfy the urdf, but it turned out all my efforts with setup.py were not actually being used.

Solution was to edit the CMakeLists.txt and add the urdf files installation.

Originally posted by RobotDreams with karma: 327 on 2021-06-29

This answer was ACCEPTED on the original site

Post score: 1


Your Answer

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