Ask Your Question
13

how to define ROS kinetic to use python3 instead of python2.7?

asked 2016-06-21 02:17:10 -0500

SHPOWER gravatar image

Hey,

I want to use Qt5 and python3 in ROS. I read that ROS kinetic should support python3. However I haven't found any instruction about the proper way to configure PYTHONPATH, CATKIN, etc. Is there any proper way that I can do that without loosing ROS functionality?

Thanks in advance

edit retag flag offensive close merge delete

Comments

Hello, did you happen to find any way to get ROS to work with Python3?

Tanmay gravatar imageTanmay ( 2016-10-03 15:02:00 -0500 )edit
1

Were you able to get ROS running for python3?

zishan gravatar imagezishan ( 2017-12-20 03:46:27 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
12

answered 2016-06-21 10:03:13 -0500

Dirk Thomas gravatar image

No ROS distribution officially supports Python 3. ROS Kinetic uses Qt 5 though, e.g. for rqt and rviz.

If you want to try it anyway you need to build everything from source (following the "normal" from source instructions). But before you will need to install all Python dependencies (e.g. catkin_pkg) for Python 3. Since the Debian packages are not side-by-side installable with the Python 2 version using a virtualenv will likely be the easiest way. The virtualenv will also ensure that python is pointing to a Python 3 interpreter. Otherwise you would need to pass a custom interpreter to the build (like -DPYTHON_EXECUTABLE=python3).

Anyway if you go that route you should expect problems and will find things which simply don't work with Python 3.

edit flag offensive delete link more

Comments

thank you.

SHPOWER gravatar imageSHPOWER ( 2016-06-22 09:06:55 -0500 )edit

Please mark the answer as accepted if it answered your question so that others find it now easily.

Dirk Thomas gravatar imageDirk Thomas ( 2016-06-22 09:36:50 -0500 )edit

As a side note; where can I find the status/plans of Python 3 adoption in ROS?

alf gravatar imagealf ( 2017-07-28 01:31:54 -0500 )edit

Were you able to get ROS running for python3?

zishan gravatar imagezishan ( 2017-12-20 03:46:24 -0500 )edit

I don't believe there is anyone working on it actively, but we are quite close to have full support. See my answer below for details.

v4hn gravatar imagev4hn ( 2018-09-08 04:26:27 -0500 )edit
5

answered 2018-09-08 04:25:26 -0500

v4hn gravatar image

The situation changed slightly over the last two years. You can compile a complete ROS distribution (I tried kinetic) with

catkin build --cmake-args -DPYTHON_VERSION=3.6

assuming you setup a whole core workspace with something like

rosinstall_generator --rosdistro kinetic desktop_full

This works more or less for the core ROS system. I just filed a few patches to make it even work with MoveIt.

However, Dirk's comment is still true. Sadly even in ROS-melodic (which very few people are using already) there is no enforced python3 support. By now, this is simply hilarious. But ROS2 will of course make everything better... :/

I had to fix a few lines of code in a number of packages I use myself (including tf), but they are all straight-forward python2-3 compatibility issues that are well documented.

So everyone, feel free to try it out and file patches if you find more python2-only code somewhere! We are not that far away from Python3 support anymore.

edit flag offensive delete link more

Comments

Can you please provide some links or a detailed description of how you built ROS with Python 3?

rajat7 gravatar imagerajat7 ( 2018-09-21 12:22:52 -0500 )edit

@rajat7 this is an old post with an accepted answer. This means that most people will not be looking here to answer questions. If you'd like help please ask your own question. The more complete your question the better answer you can expect. https://wiki.ros.org/Support has some suggestions.

tfoote gravatar imagetfoote ( 2018-09-21 12:56:05 -0500 )edit

This is the best thread for python3 discussions at the moment.

@rajat7: I believe I explained it in quite some detail above and even gave the command lines you need to run. I don't know of any links with more explanations.

v4hn gravatar imagev4hn ( 2018-09-21 17:40:27 -0500 )edit

I ran this command, solved each python error as it came and did it all again But I'm stuck at this error import rospkg ImportError: No module named rospkg How to solve this?

rajat7 gravatar imagerajat7 ( 2018-09-22 08:48:28 -0500 )edit

Edit: Solved the above error by setting PYTHONPATH. This is the latest one

File "/usr/lib/python3/dist-packages/yaml/__init__.py", line 284
class YAMLObject(metaclass=YAMLObjectMetaclass):
                          ^

SyntaxError: invalid syntax

rajat7 gravatar imagerajat7 ( 2018-09-22 08:49:28 -0500 )edit

This syntax is proper according to Python 3. It might be the case that it is still using the default python interpreter instead of python3. Do I need to pass another argument like -DPYTHON_EXECUTABLE=/usr/bin/python3?

rajat7 gravatar imagerajat7 ( 2018-09-23 00:46:49 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

5 followers

Stats

Asked: 2016-06-21 02:17:10 -0500

Seen: 23,991 times

Last updated: Sep 08 '18