使用colcon在Robomaker ROS工作区中安装python模块

问题描述

我正在使用AWS Robomaker开发基于云的机器人应用程序。我正在使用ROS Kinetic和构建工具colcon

我的机器人应用程序依赖于自定义python模块,该模块必须在我的工作区中。此python模块由colcon构建为python软件包,而不是ROS软件包。 This page解释了如何使用柔kin花,但this example显示了如何使其适应colcon。所以最后我的工作区看起来像这样:

my_workspace/
        |--src/
            |--my_module/
            |     |--setup.py
            |     |--package.xml
            |     |--subfolders and python scripts...
            |--some_ros_pkg1/  
            |--some_ros_pkg2/
            |...    

但是命令colcon build <my_workspace>生成所有ROS软件包,但无法将我的python模块作为软件包生成

这是我得到的错误

Starting >>> my-module
[54.297s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'my-module' doesn't explicitly install a marker in the package index (colcon-ros currently does it implicitly but that fallback will be removed in the future)
[54.298s] WARNING:colcon.colcon_ros.task.ament_python.build:Package 'my-module' doesn't explicitly install the 'package.xml' file (colcon-ros currently does it implicitly but that fallback will be removed in the future)



--- stderr: my-module                                                                     
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
   or: setup.py --help [cmd1 cmd2 ...]
   or: setup.py --help-commands
   or: setup.py cmd --help

error: invalid command 'egg_info'
---
Failed   <<< my-module [0.56s,exited with code 1]

我发现this issue似乎相关,因此尝试了:pip install --upgrade setuptools ...失败并显示错误消息:

Collecting setuptools
  Using cached https://files.pythonhosted.org/packages/7c/1b/9b68465658cda69f33c31c4dbd511ac5648835680ea8de87ce05c81f95bf/setuptools-50.3.0.zip
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>",line 1,in <module>
      File "setuptools/__init__.py",line 16,in <module>
        import setuptools.version
      File "setuptools/version.py",in <module>
        import pkg_resources
      File "pkg_resources/__init__.py",line 1365
        raise SyntaxError(e) from e
                                ^
    SyntaxError: invalid Syntax
    
    ----------------------------------------
Command "python setup.py egg_info" Failed with error code 1 in /tmp/pip-build-uwFamt/setuptools/

有了pip3 install --upgrade setuptools,我得到了:

Defaulting to user installation because normal site-packages is not writeable
Requirement already up-to-date: setuptools in /home/ubuntu/.local/lib/python3.5/site-packages (50.3.0)

我都拥有Python 3.5.2和Python 2.7,但我不知道colcon使用哪个。

所以我不知道下一步该怎么做,真正的问题是什么。欢迎任何帮助!

解决方法

我设法正确安装了我的软件包及其依赖项。我开发了以下方法,以防某天可能对某人有所帮助!

我的主要灵感来自this old DeepRacer repository

问题中的工作区树是错误的。它应该看起来像这样:

my_workspace/
        |--src/
            |--my_wrapper_package/
            |     |--setup.py
            |     |--my_package/
            |          |--__init__.py
            |          |--subfolders and python scripts...
            |--some_ros_pkg1/  
            |--some_ros_pkg2/
  • my_wrapper_package可能包含多个python自定义包。
  • this one是一个很好的setup.py示例。
  • 您不应该在package.xml旁边放置setup.py:colcon只会查看package.xml中声明的依赖项,并且不会收集pip包。
  • 有时可能会删除colcon在my_wrapper_packageinstall/中生成的文件夹build/。这样做会迫使colcon从头开始重建和捆绑。