ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

How do I specify the version of Python3 for ROS2?

asked 2019-12-19 08:25:10 -0500

kylerlaird gravatar image

I'm new to ROS2. I've tried to install ROS2 from packages a few times and I've run into a lot of dependency issues. Recently I cleared out versions of ROS1 and I now have ros-eloquent-desktop installed.

The problem stopping me now is that I can't easily run Python programs. ros-eloquent-rclpy 0.8.3-1bionic.20191213.05 (amd64) supports only Python 3.6. However, I have Python 3.7 installed and it is the default. When I run something like "ros2 run demo_nodes_py listener", /usr/bin/python3 is used. That is a link to python3.7, so ros2 fails.

I can change the symlink to python3.6 and it works fine. I prefer to avoid that.

I tried changing ROS_PYTHON_VERSION from "3" to "3.6" but that seems to have no effect.

I also tried changing the interpreter for /opt/ros/eloquent/bin/ros2, but that was insufficient.

ros2 clearly depends on Python3.6. Is there a clean way of specifying this? Where should I have found it?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-12-19 10:12:43 -0500

sloretz gravatar image

In short, you'll have to build from source. Here are the instructions for building ROS 2 on Linux: https://index.ros.org/doc/ros2/Instal...

I'm guessing Python 3.7 was installed from source, or a different apt repo? In general, whether or not this will work is undefined. The safe assumption is that it won't work. This is not limited to ROS or to Python. Debian packages depend on other Debian packages. Assuming you're on Ubuntu Bionic, the eloquent packages were built using python3 from the official Ubuntu Bionic apt repos, in which python3 is python 3.6.

While it should be expected not to work, in this case a technical reason it doesn't work is because rclpy builds a cpython extension. This is ABI compatible only with the same version of python used to build it (Python 3.6). There's more info about ABI compatibility of extension libraries in PEP 3149.


I can change the symlink to python3.6 and it works fine. I prefer to avoid that.

I'd strongly recommend against changing the system install of python via symlinks. Let your package manager handle that. rclpy is not the only package that will be broken. In general, once you stop using your package manager to install a package, you need to install every package that depends on it from source too.

I tried changing ROS_PYTHON_VERSION from "3" to "3.6" but that seems to have no effect.

ROS_PYTHON_VERSION is used to indicate the major version of python. Allowed values are 2 or 3. This is only useful for ROS 1, since ROS 2 only supports python 3. It was created to support conditional dependencies, see REP 149.

ros2 clearly depends on Python3.6. Is there a clean way of specifying this? Where should I have found it?

Debian packages list their dependencies. Running apt show ros-eloquent-rclpy will show that ros-eloquent-rclpy depends on libpython3.6.

edit flag offensive delete link more

Comments

OK, so really there's a dependency on the version of the python3 package (must be 3.6.*).

I'm reverting to bionic.

Thank you!

--kyler

kylerlaird gravatar image kylerlaird  ( 2019-12-19 18:25:49 -0500 )edit

@kylerlaird: please mark your question as answered by clicking the checkmark to the left of the answer.

gvdhoorn gravatar image gvdhoorn  ( 2019-12-20 03:54:38 -0500 )edit
1

so really there's a dependency on the version of the python3 package (must be 3.6.*)

to be more precise: the binary packages of ROS 2, released for Ubuntu Bionic, depend on the version of Python 3 that is shipped with Ubuntu Bionic. That happens to be v3.6.x in this case.

Reason I highlight this is that it's slightly different from what you wrote: the dependency is not explicitly on 3.6, but on whatever the default is for the platform supported for Eloquent.

As @sloretz wrote:

This is not limited to ROS or to Python. Debian packages depend on other Debian packages.

gvdhoorn gravatar image gvdhoorn  ( 2019-12-20 03:56:51 -0500 )edit

I think it's more precise to say that the binary packages of ROS2 have an undeclared dependency on python3 version 3.6.

kylerlaird gravatar image kylerlaird  ( 2019-12-20 09:09:26 -0500 )edit
2

No, I don't believe that is correct.

The dependency is on the system provided Python, which happens to be 3.6 on Bionic. It could be another version on some other OS.

The specific versions of dependencies on the different supported OS are documented in REP 2000: ROS 2 Target Platforms.

gvdhoorn gravatar image gvdhoorn  ( 2019-12-20 12:33:24 -0500 )edit

The dependency is certainly 3.6 for the package I have; it's the only one for which compiled modules are included.

# dpkg -L ros-eloquent-rclpy |grep /lib/python | cut -d\/ -f6 |sort -u
python3.6

There is nothing precise about crossing your fingers and hoping for a version of a package to be provided by a distribution. Dependencies are specified using numbers. https://www.debian.org/doc/debian-pol...

ros-eloquent-rclpy even specifies a version for "libpython3.6 (>= 3.6.5)" (but misses "<< 3.7"). The dependency for "python3 (>= 3.6), python3 (<< 3.7)" is missing, however.

There is clearly a dependency here. I don't understand your reason for keeping it a secret from the package manager.

kylerlaird gravatar image kylerlaird  ( 2019-12-20 19:28:30 -0500 )edit

We can actually rely on the fact that packages released into the system by Debian/Ubuntu will be ABI compatible with whatever we built against once it's in a released distribution. This assumption holds true of all the system libraries we build against. When you're in an unstable, or prerelease system it's not necessarily true but otherwise that's the policy.

Jumping to 3.7 will basically guarantee a breakage of ABI, (see semantic version) but it's quite possible that just changing to another patch release in 3.6 will also break the ABI and as such your extra assertions will not hold. Furthermore it could even be the same 3.6.8 software but built with different compile flags and the ABI will not be compatible. Version checks are not enough.

tl;dr If you are breaking the policy and deploying replacement libraries that are ...(more)

tfoote gravatar image tfoote  ( 2019-12-20 19:52:10 -0500 )edit

@tfoote: capping the max version as @kylerlaird seems to suggest would be a good idea though, to make the dependency on a specific version explicit.

gvdhoorn gravatar image gvdhoorn  ( 2019-12-21 04:38:26 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2019-12-19 08:25:10 -0500

Seen: 8,076 times

Last updated: Dec 19 '19