Skip to content

Instantly share code, notes, and snippets.

@Akashleena
Created September 23, 2021 05:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akashleena/4aae94f8319066a0014b9846a1cabeae to your computer and use it in GitHub Desktop.
Save Akashleena/4aae94f8319066a0014b9846a1cabeae to your computer and use it in GitHub Desktop.
Building ROS Melodic with python3 support
# quick gist to accompany post on building ROS Melodic w/python3 support
# https://www.miguelalonsojr.com/blog/robotics/ros/python3/2019/08/20/ros-melodic-python-3-build.html
# Warning: don't try to run this as a script. It probably won't work.
# remove all things python (optional)
sudo apt-get remove python-*
# remove previous installations of ROS
sudo apt-get remove ros-*
sudo apt-get remove ros-melodic-*
sudo apt-get autoremove
# setup python3 dependencies
sudo apt update
sudo apt install -y python3 python3-dev python3-pip build-essential
sudo -H pip3 install rosdep rospkg rosinstall_generator rosinstall wstool vcstools catkin_tools catkin_pkg
# initializ catkin build environment
sudo rosdep init
rosdep update
cd ~
mkdir ros_catkin_ws
cd ros_catkin_ws
# TODO: get rqt_rviz rviz_plugin_tutorials librviz_tutorial building w/python3
catkin config --init -DCMAKE_BUILD_TYPE=Release --blacklist rqt_rviz rviz_plugin_tutorials librviz_tutorial --install
# setup ROS install
rosinstall_generator desktop_full --rosdistro melodic --deps --tar > melodic-desktop-full.rosinstall
wstool init -j8 src melodic-desktop-full.rosinstall
# if packages fail to download, run the following
wstool update -j4 -t src
# setup environment and install dependencies
export ROS_PYTHON_VERSION=3
pip3 install -U -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-18.04 wxPython
# create the following script in the ros_catkin_ws directory and call it install_skip
#!/bin/bash
#Check whether root
if [ $(whoami) != root ]; then
echo You must be root or use sudo to install packages.
return
fi
#Call apt-get for each package
for pkg in "$@"
do
echo "Installing $pkg"
sudo apt-get -my install $pkg >> install.log
done
# and chmod it
chmod +x install_skip
# sed magic
sudo ./install_skip `rosdep check --from-paths src --ignore-src | grep python | sed -e "s/^apt\t//g" | sed -z "s/\n/ /g" | sed -e "s/python/python3/g"`
rosdep install --from-paths src --ignore-src -y --skip-keys="`rosdep check --from-paths src --ignore-src | grep python | sed -e "s/^apt\t//g" | sed -z "s/\n/ /g"`"
find . -type f -exec sed -i 's/\/usr\/bin\/env[ ]*python/\/usr\/bin\/env python3/g' {} +
# build ROS
catkin build
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment