Proper way to rename packages

Hello,

I have been joining this program on and off for the past few years. At some point an extra section was added to the ROS Basics in 5 days course. I am trying to prepare to teach with this and wanted to align my old files to the newer course layout. So I decide to rename some of my exercises to match. Now I am seeing this when I run catkin build:

Traceback (most recent call last):
File “/usr/bin/catkin”, line 11, in
load_entry_point(‘catkin-tools==0.5.0’, ‘console_scripts’, ‘catkin’)()
File “/usr/lib/python3/dist-packages/catkin_tools/commands/catkin.py”, line 272, in main
catkin_main(sysargs)
File “/usr/lib/python3/dist-packages/catkin_tools/commands/catkin.py”, line 267, in catkin_main
sys.exit(args.main(args) or 0)
File “/usr/lib/python3/dist-packages/catkin_tools/verbs/catkin_build/cli.py”, line 404, in main
return build_isolated_workspace(
File “/usr/lib/python3/dist-packages/catkin_tools/verbs/catkin_build/build.py”, line 299, in build_isolated_workspace
built_packages, unbuilt_pkgs = get_built_unbuilt_packages(context, workspace_packages)
File “/usr/lib/python3/dist-packages/catkin_tools/verbs/catkin_build/build.py”, line 164, in get_built_unbuilt_packages
find_packages(context.package_metadata_path(), warnings=).items()])
File “/usr/lib/python3/dist-packages/catkin_pkg/packages.py”, line 96, in find_packages
raise RuntimeError(’\n’.join(duplicates))
RuntimeError: Multiple packages found with the same name “exercise_3_1”:

  • excercise_21
  • exercise_3_1
    Multiple packages found with the same name “exercise_3_2”:
  • excercise_22
  • exercise_3_2
    Multiple packages found with the same name “exercise_3_3”:
  • excercise_23
  • exercise_3_3

I can’t find any instance of the old names. What do I need to do to get back to being able to build? Is there a proper way to rename packages?

Best regards,
Mike Wescott

Hi,

So that means that at some point, you’ve named more than one package exercise_3_2 and exercise_3_3. Go to each of those packages specified and look for folders with the same name:

cd ~/catkin_ws/src
find . -iname exercise_3_2

If you can only find one, then maybe some of those names are still in the build/ and devel/ folders, so deleting them and recompiling again might solve the error

cd ~/catkin_ws
rm -rf build/ devel/

That is what I did. I renamed 3 of them. I did discover that I can run catkin_make and it works fine. If I switch back to catkin build is when I see that. I now discovered that the original excercise_22 and excercise_23 need renamed again because they are actually in section 4 now. Is there a proper way to rename a package.

There are no files anywhere with the old names either as the file name or in the files. Unless there are hidden files somewhere.

Adding to @roalgoal’s point, renaming a package is not that simple. It’s not as simple as renaming the package folder.

You also need to change the package name everywhere it has been written before, especially CMakeLists.txt and package.xml. Then you would need to remove the build and devel folders and compile again. It’s error prone and should be avoided if possible.

I was aware of this and did all these steps and it still seems to find something using catkin build. Not sure why catkin_make seems to work though. I used the find and replace utility in the IDE to replace all instances.

catkin_make and catkin build don’t work together. When you need to switch from one to the other, you need to:

cd ~/catkin_ws
rm -rf build/ devel/