Ask Your Question

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

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

SHPOWER gravatar image


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


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

Were you able to get ROS running for python3?

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

3 Answers

Sort by ยป oldest newest most voted

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

Dirk Thomas gravatar image

updated 2019-08-27 11:43:14 -0500

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.


things are changing with the Noetic release coming up in less than a year which does target Python 3. Please see the latest instructions in the wiki about the topic:

edit flag offensive delete link more


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

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


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. 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/", 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

answered 2019-08-19 04:09:35 -0500

gvdhoorn gravatar image

updated 2019-08-27 03:15:49 -0500

This will likely become obsolete with the release of Noetic, but as I've just had to build a version of Kinetic with Python 3 support (for the Nth time), I figured I'd post the commands I've used here (for myself as well).

This is a more copy-pastable version of @v4hn's answer (but was too long for a comment).


  • OS: Ubuntu Xenial (16.04)
  • ROS Kinetic is already installed on that system (the .deb distributed version)

I always use a virtual environment, as it's typically the case that besides ROS, there are Python modules that need to be installed one might not want to "pollute" the system with.


  1. this only builds a bare-bones ROS Kinetic with Python 3. No Open CV or other 'complex' packages/nodes. For many use-cases this is already quite sufficient though.
  2. as such, this is not an answer to the general problem of how to build all of ROS 1 with Python 3 support.

In any case, as follows:

# create a place for our Python3-ROS-Kinetic to live
mkdir $HOME/rospy3_kinetic
cd $HOME/rospy3_kinetic

# make sure these are installed
apt install python3-venv libpython3-dev python-catkin-tools

python3.5 -m venv venv3.5_ros
source venv3.5_ros/bin/activate

# these modules are needed but are not automatically installed
pip3 install wheel empy defusedxml netifaces

# just the standard build-ros-from-source dependencies
pip3 install -U rosdep rosinstall_generator wstool rosinstall

# seed the workspace with a 'ros_base' set of packages
rosinstall_generator --deps --tar --rosdistro=kinetic ros_base > ros_base.rosinstall
wstool init src -j8 ros_base.rosinstall

# the following is somewhat optional: I like to run this to see if
# something obvious is missing, but we can't ask rosdep to 'install'
# things for us: it will try to use apt to install the Python 2 version
# of all dependencies it sees missing.

# this may fail if you already have done this, in that case: ignore
sudo rosdep init
rosdep update

# I use check here to first see what is missing. If missing dependencies are
# serious enough, use 'pip3' to install into the virtual environment for
# Python dependencies, 'apt' for any other dependencies
rosdep check --from-paths src/ -i

# finally build the workspace, while:
#  - disabling testing globally
#  - making sure optimisations are enabled ('Release' build type)
#  - forcing use of Python 3.5

At this point source the setup.bash of the workspace. You may choose to configure catkin_tools to create an install space instead of using the devel space directly.

For regular usage you'll need to make sure to have the virtual environment activated, or things will break.

I'd recommend using workspace overlaying for actual development.

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools



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

Seen: 26,320 times

Last updated: Aug 27