Building ROS from sources in a python3 virtualenv

asked 2017-10-02 19:00:33 -0500

owerko gravatar image

updated 2017-10-04 19:14:03 -0500

While ROS2 is a WIP, I am working on using python3 with ros (kinetic). To do this I am installing it from sources. However since I am installing it from sources anyways, I decided it might be a better idea to install it inside a virtualenv. That way both a python2 and a python3 version could be used on the same machine. This initially started as an attempt to write nodes in python3 rather than python2, mainly due to abundance of new features such as the typing module.

I want to know whether or not this is actually possible or do I have a major misunderstanding of things.

Currently I am using the following bash script to install everything. Compiling still fails, but I managed to get more and more packages to compile. This is all meant for Ubuntu 16.04.

This is the script I am using:

#!/bin/bash

########################################vo
## PATH VARIABLES
########################################
env_name=environment
path=~/PennAiR

mkdir -p $path
cd $path
directory=$(pwd)

section (){
    CYAN='\033[36;1m'
    NC='\033[0m'
    printf "${CYAN}"
    printf "#################################\n"
    printf "$1\n"
    printf "#################################\n"
    printf "${NC}"
}

########################################
## DEPENDENCIES AND UTILS
########################################
sudo apt -y install git python3-dev mercurial

########################################
## SETUP VIRTUALENV
########################################
section "SETUP VIRTUALENV"

sudo apt update
sudo apt install python-pip
pip install --upgrade setuptools
pip install virtualenv

cd $directory
virtualenv -p /usr/bin/python3 $env_name
echo "source $directory/$env_name/bin/activate" >> $directory/activate
chmod +x $directory/activate

########################################
## ROS SETUP FROM SOURCES
########################################
section "ROS SETUP FROM SOURCES"

sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release -sc) main" > /etc/apt/sources.list.d/ros-latest.list'
sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-key 421C365BD9FF1F717815A3895523BAEEB01FA116
sudo apt update

cd $directory

source activate
pip install -U git+https://github.com/ros-infrastructure/rosdep.git@master
pip install -U rosinstall_generator wstool rosinstall catkin_pkg


echo "export ROS_ETC_DIR=$directory/$env_name/etc/ros" >> $directory/activate
if [ -z "$PYTHONPATH" ]
then
      echo "export PYTHONPATH=$directory/$env_name/lib/python3.5/site-packages:$PYTHONPATH" >> $directory/activate
else
      echo "export PYTHONPATH=$directory/$env_name/lib/python3.5/site-packages" >> $directory/activate
fi

deactivate
source activate
rosdep init
rosdep update

section "INITIALIZE ROS CATKIN WORKSPACE"
mkdir ros_catkin_ws
cd ros_catkin_ws
rosinstall_generator desktop_full --rosdistro kinetic --deps --wet-only --tar > kinetic-desktop-full-wet.rosinstall
wstool init -j1 src kinetic-desktop-full-wet.rosinstall
rosdep install --from-paths src --ignore-src --rosdistro kinetic -y --as-root=pip:false

#build
section "BUILD ROS"

PYTHON_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())")
PYTHON_LIBRARY=$(python -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))")

wget -qO- https://downloads.sourceforge.net/project/pyqt/sip/sip-4.19.3/sip-4.19.3.tar.gz | tar xvz
cd sip-4.19.3
python configure.py
make
sudo make install
cd ..

./src/catkin/bin/catkin_make_isolated --install -DCMAKE_BUILD_TYPE=Release -DPYTHON_INCLUDE_DIR=$PYTHON_INCLUDE_DIR -DPYTHON_LIBRARY=$PYTHON_LIBRARY --install-space $directory/$env_name/opt/ros/kinetic

########################################
## SETUP MAVLINK MAVROS
########################################
#cd $directory
#source $envname/

#mkdir -p ~/catkin_ws/src
#cd ~/catkin_ws

I am currently stuck on compiling rospack from sources:

==> Processing catkin package: 'rospack'
==> Building with env: '/home/pennair/PennAiR/ros/kinetic/env.sh'
==> cmake /home/pennair/PennAiR/ros_catkin_ws/src/rospack -DCATKIN_DEVEL_PREFIX=/home/pennair/PennAiR ...
(more)
edit retag flag offensive close merge delete

Comments

Could I ask you to please include the script and the error text into your question text proper? Use the Preformatted Code button (the one with 101010 on it) for that.

If your pastebins ever go away -- and they will -- your question loses much of its value.

gvdhoorn gravatar image gvdhoorn  ( 2017-10-04 01:48:14 -0500 )edit

Where you able to setup ROS with python3?

zishan gravatar image zishan  ( 2017-12-20 04:01:43 -0500 )edit

No, we ended up using python2 since this was taking too much time. I still believe that most packages would work, since they should by python3 compatible by REP standards.

owerko gravatar image owerko  ( 2017-12-20 14:37:42 -0500 )edit

While existing packages are requested to be compatible, most have not been tested adequately with Python3, because that's quite a lot of work.

joq gravatar image joq  ( 2017-12-25 10:53:01 -0500 )edit

There is a new effort afoot to make compatibility easier: https://github.com/ros-infrastructure...

joq gravatar image joq  ( 2017-12-25 10:54:12 -0500 )edit

Have you explored using RoboStack https://github.com/RoboStack/ros-noetic. Works well with Ubuntu and allows to install ROS in virtual environment. I run Noetic with little issues and the support group is very good.

osilva gravatar image osilva  ( 2021-09-22 08:50:27 -0500 )edit