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

Revision history [back]

click to hide/show revision 1
initial version

The solution to not mixing python2 and python3 is to have workspaces with only python2 or python3 and to never invoke the other python within that system. You will have to build everything from source as the debian packages are built for the default version of python (2) in melodic.

The simplest way to do this is to setup a virualenv and then do the standard compile from source. https://docs.python.org/3/tutorial/venv.html

If you don't use the virtualenv there are a few paths and settings that you may need to update.

http://wiki.ros.org/UsingPython3/BuildUsingPython3

I found a tutorial here that looks like it's pretty up to date: https://www.miguelalonsojr.com/blog/robotics/ros/python3/2019/08/20/ros-melodic-python-3-build.html

There's also several answers on answers.ros.org like https://answers.ros.org/question/237613/how-to-define-ros-kinetic-to-use-python3-instead-of-python27/

But in general this isn't a supported target so it's not a process for which we're optimizing.


Related to the fact that this isn't supported. At a higher level I'd recommend that for the duration of the remaining period of support for Melodic that you simply write your code to be compatible with both python2 and python3. It's takes a relatively low overhead and all of the core packages are written that way. We have a guide to do this at: http://wiki.ros.org/python_2_and_3_compatible_code