Make it easy to install the ROS2 development environment with pip install on Python venv

Introduction

ROS Advent Calendar 2020 This is the article on the 22nd day. This year, ROS2 has become quite popular, and the transition to ROS2 has become realistic, such as support for ROS2 in major libraries. Next year, 2021, the transition to ROS2 is expected to progress further (arbitrary forecast).

I'm finally starting to touch ROS2, but the OS I'm using is 18.04, which is a little old and I can't try the latest foxy. There are ways to build from source or use Docker, but the source needs to be built every time, and Docker needs to be mounted at the time of development, so the authority is a little troublesome.

Therefore,

  1. It can be installed in any directory without root privileges, and the environment can be easily built and destroyed.
  2. Try ROS2 on multi-platform Ubuntu, Mac, Windows and Python 3.6-3.9

Aiming for that, I made it possible to install ROS2 with the Wheel package of Python, so I will introduce it.

The confirmed environment is as follows.

How to use

Installation

#Environment
$ python3 --version
Python 3.6.9
$ python3 -m venv venv
$ . ./venv/bin/activate
(venv) $ pip install -U pip

#Installation
(venv) $ pip install --extra-index-url https://rospypi.github.io/simple2 rclpy std_msgs ros2py-init
...(Abbreviation) ..

#Run only once
(venv) $ ros2py-init
updated

#If you want to use it as it is, deactivate it once and activate it again.
(venv) $ deactivate
$ . ./venv/bin/activate
LD_LIBRARY_PATH=....

Try the sample (Python)

Get sample code

git clone https://github.com/ros2/examples.git

Open a new terminal and run Publisher.

$ . ./venv/bin/activate
LD_LIBRARY_PATH=....
(venv) $ python examples/rclpy/topics/minimal_publisher/examples_rclpy_minimal_publisher/publisher_member_function.py
[INFO] [1608563828.438826436] [minimal_publisher]: Publishing: "Hello World: 0"
[INFO] [1608563828.931807019] [minimal_publisher]: Publishing: "Hello World: 1"
[INFO] [1608563829.430286609] [minimal_publisher]: Publishing: "Hello World: 2"
[INFO] [1608563829.931504088] [minimal_publisher]: Publishing: "Hello World: 3"
[INFO] [1608563830.430435935] [minimal_publisher]: Publishing: "Hello World: 4"
[INFO] [1608563830.931712417] [minimal_publisher]: Publishing: "Hello World: 5"
[INFO] [1608563831.430346898] [minimal_publisher]: Publishing: "Hello World: 6"

Open a new terminal and run Subscriber.

$ . ./venv/bin/activate
LD_LIBRARY_PATH=....
(venv) $ python rclpy/topics/minimal_subscriber/examples_rclpy_minimal_subscriber/subscriber_member_function.py
[INFO] [1608563893.706370811] [minimal_subscriber]: I heard: "Hello World: 17"
[INFO] [1608563894.199072027] [minimal_subscriber]: I heard: "Hello World: 18"
[INFO] [1608563894.702395055] [minimal_subscriber]: I heard: "Hello World: 19"
[INFO] [1608563895.202343741] [minimal_subscriber]: I heard: "Hello World: 20"
[INFO] [1608563895.701980945] [minimal_subscriber]: I heard: "Hello World: 21"
[INFO] [1608563896.202263923] [minimal_subscriber]: I heard: "Hello World: 22"
[INFO] [1608563896.701910239] [minimal_subscriber]: I heard: "Hello World: 23"

You can create a ROS2 execution environment anywhere without root privileges, building from source, or using Docker.

About the contents

The Python package can include files such as include, lib, and share in the distribution package, starting from sys.prefix. This time, I used this to put all the files included in each ROS2 package into a Python package. By doing this, sys.prefix can be treated like/opt/ros/foxy (AMENT_PREFIX_PATH), so you can build the ROS2 execution environment by passing through LD_LIBRARY_PATH. Since all include files, so files, ament_cmake, etc. for C and C ++ are installed, it seems that you can build and execute the ROS2 package in this state as long as you write CMake for ROS2 (you can try it). I will introduce it again)

The script to create a Python package is available at https://github.com/otamachan/ros2py.git.

in conclusion

Actually, I wanted to bring it to the point where I could do pip install rviz2, but I didn't have enough time. However, I am satisfied in the sense that ROS2 can be easily installed on both MacOS and Ubuntu for the time being. The Python wheel can do almost something like apt in the sense that it distributes pre-built binaries, and the ROS2 build supports (complexes) the environment ament_cmake. It was this lesson that I was able to go around.

In the future, I would like to support the following TODO.

Happy Robot Programming!

Recommended Posts

Make it easy to install the ROS2 development environment with pip install on Python venv
Prepare the development environment for Python on AWS Cloud9 (pip install & time change)
Install Python development environment on Windows 10
How to get into the python development environment with Vagrant
Steps to install Python environment on Ubuntu
scipy stumbles with pip install on python 2.7.8
Install python on xserver to use pip
Install the python module with pip on a server without root privileges
[Zaif] I tried to make it easy to trade virtual currencies with Python
Introduction to Python Let's prepare the development environment
Introduction to Python with Atom (on the way)
Make your Python environment "easy" with VS Code
Make it easy to specify the time of AWS CloudWatch Events with CDK.
Prepare a development environment that is portable and easy to duplicate without polluting the environment with Python embeddable (Windows)
Install Python venv --VSCode --GitHub integration environment on Mac
Install selenium on Mac and try it with python
Install Ubuntu 20.04 with GUI and prepare the development environment
Install Python environment on local PC (pyenv, venv on Mac)
An easy way to pad the number with zeros depending on the number of digits [Python]
How to set the development environment for each project with VSCode + Python extension + Miniconda
I tried to make it easy to change the setting of authenticated Proxy on Jupyter
It is easy to execute SQL with Python and output the result in Excel
Install Python environment with Anaconda
Easy to make with syntax
How to install Python2.7 python3.5 with pyenv (on RHEL5 CentOS5) (2016 Nov)
[Road to intermediate Python] Install packages in bulk with pip
Unify the environment of the Python development team starting with Poetry
The first API to make with python Djnago REST framework
Move what you installed with pip to the conda environment
How to build a python2.7 series development environment with Vagrant
Save images on the web to Drive with Python (Colab)
Install CaboCha in Ubuntu environment and call it with Python.
[No venv required] The strongest Python development environment created with Remote Containers [VS Code / Docker]
I want to set up a GUI development environment with Python or Golang on Mac
I set the python operating environment on OSX Yosemite (pyenv + pip)
Life game with Python [I made it] (on the terminal & Tkinter)
Install Python 2.7.9 and Python 3.4.x with pip.
How to install OpenCV on Cloud9 and run it in Python
Prepare Python development environment on Ubuntu
Easy way to round off to the nearest whole number with python3
What to do if you can't install pyaudio with pip #Python
Install python2.7 on windows 32bit environment
Install Python on Windows + pip + virtualenv
Continuation ・ Notes on preparing the Python development environment on Mac OS X
[Python] What is pip? Explain the command list and how to use it with actual examples
Easy to install pyspark with conda
Install the Python plugin with Netbeans 8.0.2
Python development environment construction on macOS
Install packages that need to be compiled with Python3 with pip [Windows]
Unable to install Python with pyenv
Install pip in Serverless Framework and AWS Lambda with Python environment
[TensorFlow] If you want to run TensorBoard, install it with pip
Install lp_solve on Mac OS X and call it with python.
Build Python environment on Ubuntu (when pip is not the default)
How to install mysql-connector with pip3
Checking the NAOqi Python development environment
Steps to install python3 on mac
Prepare Python development environment with Atom
[Python] Make pip available on macOS
Prepare the development environment with anyenv
[Python Windows] pip install with Python version