5. Building ROS Melodic with Python 3 Support - sundevilrobotics/urc-code GitHub Wiki
After a tremendous amount of testing and research, I finally found a way to compile a ROS Melodic catkin workspace with Python 3 support. Here are the steps (thanks to https://dhanoopbhaskar.com/blog/2020-05-07-working-with-python-3-in-ros-kinetic-or-melodic/ for help/inspiration!):
- If you run
catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3
in~/catkin_ws
, you should get an error such asCMake Error
fromNo module named 'catkin_pkg'
or something similar. If it compiles successfully, congratulations, you already have your catkin workspace working with Python 3. - Run
sudo apt install python3-pip python3-all-dev python3-rospkg
. This will uninstall ROS (since it only has support for Python 2), so we will need to reinstall ROS and all of our ROS package dependencies in the following steps. - Run
sudo apt install ros-melodic-desktop-full --fix-missing
with the ROS install type (desktop-full, desktop, or bare-bones) of your choosing. This will install ROS again with the correct Python 3 (and Python 2) support. cd ~/catkin_ws/src/urc-code
and runchmod +x install.sh
and then./install.sh
again to reinstall our urc-code dependencies.cd ~/catkin_ws/
and runcatkin_make -DPYTHON_EXECUTABLE=/usr/bin/python3
again. You should see the line-- Found PythonInterp: /usr/bin/Python3 (found version "3.X.X")
near the top of the catkin_make output. If the catkin_make completes without errors, you have successfully compiled your catkin workspace with Python 3 support!
Additionally, I also needed to:
- Run
sudo apt install python3-empy
to fix an compilation error (ImportError: No module named 'em'
)
If you ever need to compile with Python 2 in the future, you can switch back by running a catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python2.7
or maybe a catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python2
or even potentially a catkin_make -DPYTHON_EXECUTABLE=/usr/bin/python
.
Please continue to contribute to this page, updating it with additional dependencies needed like the python3-empy
package installed in step 6.