Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@Strong30Impact
Copy link

Strong30Impact commented Jun 18, 2020

Oi @metalglove , eu preciso do pyhton3 no ROS para um projeto e segui a postagem do seu blog e sua publicação em 2 de abril e me dá um erro quando aplico a seguinte linha:

# install python 3 packages
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"`
Installing python3-rospkg
Installing python3-mock
Installing python3-empy
Installing python3-catkin-pkg-modules
E: Unable to locate package python3-catkin-pkg-modules
Installing python3-rosdep-modules
E: Unable to locate package python3-rosdep-modules
Installing python3-coverage
Installing python3-rospkg-modules
E: Unable to locate package python3-rospkg-modules
Installing python3-nose
Installing python3-paramiko
Installing python3-pycryptodome
Installing python3-gnupg
Installing python3-defusedxml
Installing python3-pyqt5.qtopengl
Installing python3-cairo
Installing python3-pil
Installing python3-psutil
Installing python3-pyqt5.qtsvg
Installing python3-catkin-pkg
Installing python3-dev
Installing python3-opencv
Installing python3-numpy
Installing python3-matplotlib
Installing python3-opengl
Installing python3-wxtools
E: Unable to locate package python3-wxtools
Installing python3-sip-dev
Installing python3-pydot
Installing python3-pygraphviz
Installing python3-pyqt5.qtwebkit

Se eu continuar com a instalação quando eu faço "catkin build", este erro ocorre:

[build] Summary: All 204 succeeded packages!                                   
[build]   Ignored: 33 packages were skipped or are blacklisted.              
[build]   Warnings: 13 packages succeeded with warnings.                      
[build]   Abandoned: None.                                                     
[build]   Failed: None.                                                     
[build] Runtime: 13 minutes and 13.8 seconds total.                            
[build] Note: Workspace packages have changed, please re-source setup files to use them.
Exception ignored in: <bound method BaseEventLoop.__del__ of <_UnixSelectorEventLoop running=False closed=True debug=False>>
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/trollius/base_events.py", line 395, in __del__
  File "/usr/local/lib/python3.6/dist-packages/trollius/unix_events.py", line 65, in close
  File "/usr/local/lib/python3.6/dist-packages/trollius/unix_events.py", line 166, in remove_signal_handler
  File "/usr/lib/python3.6/signal.py", line 47, in signal

TypeError: signal handler must be signal. SIG_IGN, signal. SIG_DFL, or a callable object

Se eu tentar "roscore" no final de tudo, me dá erro. Segui as sugestões do post anterior e nada. Você poderia me ajudar por favor? obrigado

It was not my blog post, but I took an interest in this script. I have since moved to ROS neotic (which supports python 3 by default).
http://wiki.ros.org/noetic

@metalglove But did you get python3 up and running with ROS Melodic?
My code have to run on the nano jetson and I believe there is no ros noetic installation for it, just Melodic.
So it's very important for me to get ROS Melodic up and running with python3

@graemerae
Copy link

graemerae commented Jun 18, 2020

Noob here. Trying to run catkin config --init -DCMAKE_BUILD_TYPE=Release --blacklist rqt_rviz rviz_plugin_tutorials librviz_tutorial --install, I get the following error:

Traceback (most recent call last):
  File "/usr/local/bin/catkin", line 6, in <module>
    from catkin_tools.commands.catkin import main
  File "/usr/local/lib/python3.7/dist-packages/catkin_tools/commands/catkin.py", line 28, in <module>
    from catkin_tools.common import is_tty
  File "/usr/local/lib/python3.7/dist-packages/catkin_tools/common.py", line 23, in <module>
    import trollius as asyncio
  File "/usr/local/lib/python3.7/dist-packages/trollius/__init__.py", line 21, in <module>
    from .base_events import *
  File "/usr/local/lib/python3.7/dist-packages/trollius/base_events.py", line 42, in <module>
    from . import tasks
  File "/usr/local/lib/python3.7/dist-packages/trollius/tasks.py", line 565
    def async(coro_or_future, loop=None):
            ^
SyntaxError: invalid syntax

I am trying to follow the instructions on a Raspberry Pi running Raspbian Buster Lite and had previously installed Ros Melodic from source according to this tutorial. Before trying the instructions above, I simply deleted my existing ros_catkin_ws and catkin_ws.

Noob here. Trying to run catkin config --init -DCMAKE_BUILD_TYPE=Release --blacklist rqt_rviz rviz_plugin_tutorials librviz_tutorial --install, I get the following error:

Traceback (most recent call last):
  File "/usr/local/bin/catkin", line 6, in <module>
    from catkin_tools.commands.catkin import main
  File "/usr/local/lib/python3.7/dist-packages/catkin_tools/commands/catkin.py", line 28, in <module>
    from catkin_tools.common import is_tty
  File "/usr/local/lib/python3.7/dist-packages/catkin_tools/common.py", line 23, in <module>
    import trollius as asyncio
  File "/usr/local/lib/python3.7/dist-packages/trollius/__init__.py", line 21, in <module>
    from .base_events import *
  File "/usr/local/lib/python3.7/dist-packages/trollius/base_events.py", line 42, in <module>
    from . import tasks
  File "/usr/local/lib/python3.7/dist-packages/trollius/tasks.py", line 565
    def async(coro_or_future, loop=None):
            ^
SyntaxError: invalid syntax

I am trying to follow the instructions on a Raspberry Pi running Raspbian Buster Lite and had previously installed Ros Melodic from source according to this tutorial. Before trying the instructions above, I simply deleted my existing ros_catkin_ws and catkin_ws.

Thank you very much for any help!

I solved this one by a hack. Apparently there's a bug in that tasks file for the version of python we both seem to be using. (Are you on a raspberry PI?) I simply edited /usr/local/lib/python3.7/dist-packages/trollius/tasks.py and deleted the 'async' reference at the top of the file and then deleted the entire function at line 565. (it even says it's been deprecated)
Discussed here: catkin/catkin_tools#558

@Strong30Impact
Copy link

Strong30Impact commented Jun 18, 2020

Noob here. Trying to run catkin config --init -DCMAKE_BUILD_TYPE=Release --blacklist rqt_rviz rviz_plugin_tutorials librviz_tutorial --install, I get the following error:

Traceback (most recent call last):
  File "/usr/local/bin/catkin", line 6, in <module>
    from catkin_tools.commands.catkin import main
  File "/usr/local/lib/python3.7/dist-packages/catkin_tools/commands/catkin.py", line 28, in <module>
    from catkin_tools.common import is_tty
  File "/usr/local/lib/python3.7/dist-packages/catkin_tools/common.py", line 23, in <module>
    import trollius as asyncio
  File "/usr/local/lib/python3.7/dist-packages/trollius/__init__.py", line 21, in <module>
    from .base_events import *
  File "/usr/local/lib/python3.7/dist-packages/trollius/base_events.py", line 42, in <module>
    from . import tasks
  File "/usr/local/lib/python3.7/dist-packages/trollius/tasks.py", line 565
    def async(coro_or_future, loop=None):
            ^
SyntaxError: invalid syntax

I am trying to follow the instructions on a Raspberry Pi running Raspbian Buster Lite and had previously installed Ros Melodic from source according to this tutorial. Before trying the instructions above, I simply deleted my existing ros_catkin_ws and catkin_ws.

Noob here. Trying to run catkin config --init -DCMAKE_BUILD_TYPE=Release --blacklist rqt_rviz rviz_plugin_tutorials librviz_tutorial --install, I get the following error:

Traceback (most recent call last):
  File "/usr/local/bin/catkin", line 6, in <module>
    from catkin_tools.commands.catkin import main
  File "/usr/local/lib/python3.7/dist-packages/catkin_tools/commands/catkin.py", line 28, in <module>
    from catkin_tools.common import is_tty
  File "/usr/local/lib/python3.7/dist-packages/catkin_tools/common.py", line 23, in <module>
    import trollius as asyncio
  File "/usr/local/lib/python3.7/dist-packages/trollius/__init__.py", line 21, in <module>
    from .base_events import *
  File "/usr/local/lib/python3.7/dist-packages/trollius/base_events.py", line 42, in <module>
    from . import tasks
  File "/usr/local/lib/python3.7/dist-packages/trollius/tasks.py", line 565
    def async(coro_or_future, loop=None):
            ^
SyntaxError: invalid syntax

I am trying to follow the instructions on a Raspberry Pi running Raspbian Buster Lite and had previously installed Ros Melodic from source according to this tutorial. Before trying the instructions above, I simply deleted my existing ros_catkin_ws and catkin_ws.
Thank you very much for any help!

I solved this one by a hack. Apparently there's a bug in that tasks file for the version of python we both seem to be using. (Are you on a raspberry PI?) I simply edited /usr/local/lib/python3.7/dist-packages/trollius/tasks.py and deleted the 'async' reference at the top of the file and then deleted the entire function at line 565. (it even says it's been deprecated)
Discussed here: catkin/catkin_tools#558

I'm using nvidia's jetson nano. I searched and found no ROS2 installation that already has python3 nor ros noetic. That's why it's important to be able to install. Did you even use some algorithm in python3 and it worked well? Deep Learning algorithm? @metalglove

@graemerae
Copy link

graemerae commented Jun 18, 2020

I knew this was going too well:

Errors     << xmlrpcpp:make /home/pi/ros_catkin_ws/logs/xmlrpcpp/build.make.000.log                         
/home/pi/ros_catkin_ws/src/ros_comm/xmlrpcpp/src/XmlRpcClient.cpp: In member function �virtual std::__cxx11::string XmlRpc::XmlRpcClient::generateHeader(size_t) const�:
/home/pi/ros_catkin_ws/src/ros_comm/xmlrpcpp/src/XmlRpcClient.cpp:330:3: error: �snprintf� is not a member of �std�
   std::snprintf(buff,40,":%d\r\n", _port);
   ^
/home/pi/ros_catkin_ws/src/ros_comm/xmlrpcpp/src/XmlRpcClient.cpp:330:3: note: suggested alternative:
In file included from /home/pi/ros_catkin_ws/src/ros_comm/xmlrpcpp/src/XmlRpcClient.cpp:8:0:
/usr/include/stdio.h:354:12: note:   �snprintf�
 extern int snprintf (char *__restrict __s, size_t __maxlen,
            ^
/home/pi/ros_catkin_ws/src/ros_comm/xmlrpcpp/src/XmlRpcClient.cpp:335:3: error: �snprintf� is not a member of �std�
   std::snprintf(buff,40,"%zu\r\n\r\n", length);
   ^
/home/pi/ros_catkin_ws/src/ros_comm/xmlrpcpp/src/XmlRpcClient.cpp:335:3: note: suggested alternative:
In file included from /home/pi/ros_catkin_ws/src/ros_comm/xmlrpcpp/src/XmlRpcClient.cpp:8:0:
/usr/include/stdio.h:354:12: note:   �snprintf�
 extern int snprintf (char *__restrict __s, size_t __maxlen,
            ^
make[2]: *** [CMakeFiles/xmlrpcpp.dir/build.make:63: CMakeFiles/xmlrpcpp.dir/src/XmlRpcClient.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:137: CMakeFiles/xmlrpcpp.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
cd /home/pi/ros_catkin_ws/build/xmlrpcpp; catkin build --get-env xmlrpcpp | catkin env -si  /usr/bin/make --jobserver-auth=3,4; cd -

Any thoughts?

@graemerae
Copy link

graemerae commented Jun 21, 2020

I knew this was going too well:

Errors << xmlrpcpp:make /home/pi/ros_catkin_ws/logs/xmlrpcpp/build.make.000.log
/home/pi/ros_catkin_ws/src/ros_comm/xmlrpcpp/src/XmlRpcClient.cpp: In member function �virtual std::__cxx11::string XmlRpc::XmlRpcClient::generateHeader(size_t) const�:
/home/pi/ros_catkin_ws/src/ros_comm/xmlrpcpp/src/XmlRpcClient.cpp:330:3: error: �snprintf� is not a member of �std�
std::snprintf(buff,40,":%d\r\n", _port);
^
/home/pi/ros_catkin_ws/src/ros_comm/xmlrpcpp/src/XmlRpcClient.cpp:330:3: note: suggested alternative:
In file included from /home/pi/ros_catkin_ws/src/ros_comm/xmlrpcpp/src/XmlRpcClient.cpp:8:0:
/usr/include/stdio.h:354:12: note: �snprintf�
extern int snprintf (char *__restrict __s, size_t __maxlen,
^
/home/pi/ros_catkin_ws/src/ros_comm/xmlrpcpp/src/XmlRpcClient.cpp:335:3: error: �snprintf� is not a member of �std�
std::snprintf(buff,40,"%zu\r\n\r\n", length);
^
/home/pi/ros_catkin_ws/src/ros_comm/xmlrpcpp/src/XmlRpcClient.cpp:335:3: note: suggested alternative:
In file included from /home/pi/ros_catkin_ws/src/ros_comm/xmlrpcpp/src/XmlRpcClient.cpp:8:0:
/usr/include/stdio.h:354:12: note: �snprintf�
extern int snprintf (char *__restrict __s, size_t __maxlen,
^
make[2]: *** [CMakeFiles/xmlrpcpp.dir/build.make:63: CMakeFiles/xmlrpcpp.dir/src/XmlRpcClient.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:137: CMakeFiles/xmlrpcpp.dir/all] Error 2
make: *** [Makefile:141: all] Error 2
cd /home/pi/ros_catkin_ws/build/xmlrpcpp; catkin build --get-env xmlrpcpp | catkin env -si /usr/bin/make --jobserver-auth=3,4; cd -
Any thoughts?

I solved this by wiping the SD card on my pi and reinstalling from scratch.

@graemerae
Copy link

graemerae commented Jun 21, 2020

The complete script for installing ROS with python3.

# ensure there are no ros packages
sudo apt-get remove --autoremove ros-*

# check for updates
sudo apt update

# ensure /etc/ros removal
sudo rm -rf /etc/ros/

# install the python3 libraries 
sudo apt install -y python3 python3-dev python3-pip build-essential

# Remove python2
sudo apt purge -y python2.7-minimal

# link python -> python3
sudo ln -s /usr/bin/python3 /usr/bin/python

# Same for pip
sudo ln -s /usr/bin/pip3 /usr/bin/pip

# install the ros dependencies
sudo -H pip3 install rosdep rospkg rosinstall_generator rosinstall wstool vcstools catkin_tools catkin_pkg

# initialize catkin build environment
sudo rosdep init && rosdep update

# create catkin workspace
mkdir -p ~/ros_catkin_ws/src && cd "$_/.."

# initialize catkin workspace (will show warning about Extending... ignore that)
catkin config --init -DCMAKE_BUILD_TYPE=Release --blacklist rqt_rviz rviz_plugin_tutorials librviz_tutorial --install

# generate a ros melodic install
rosinstall_generator desktop_full --rosdistro melodic --deps --tar > melodic-desktop-full.rosinstall

# initialize the install
wstool init -j8 src melodic-desktop-full.rosinstall

# setup environment and install dependencies
export ROS_PYTHON_VERSION=3

# install wxPython
pip install -U -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-18.04 wxPython

# create install_skip file
printf '#/bin/bash\nif [ $(whoami) != root ]; then\n    echo You must be root or use sudo to install packages.\n    return\nfi\n\nfor pkg in "$@"\ndo\n    echo "Installing $pkg"\n    sudo apt-get -my install $pkg >> install.log\ndone' > install_skip

# make file executable
chmod +x install_skip

# install python 3 packages
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"`

# skip python 2 packages
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"`"

# rename all old python links to python3
find . -type f -exec sed -i 's/\/usr\/bin\/env[ ]*\<python\>/\/usr\/bin\/env python3/g' {} +

# remove all depricated install-layout=deb arguments
find ./ -name 'python_distutils_install.sh' -exec sed -i 's/--install-layout=deb//g' {} \;

# install python-empy
sudo apt install -y python-empy

# build ros
catkin build

# export python path
export PYTHONPATH=/usr/lib/python3/dist-packages

# source setup
source ~/ros_catkin_ws/install/setup.bash

I also had massive problems with installing wxTools, so I skipped as I didn't need it (everything I do is headless). I also changed my build to a ros_base instead of a desktop_full.

So if anyone is coming here to successfully build melodic on a headless raspberryPi ZeroW running rasbian buster the changes I needed were:

  1. CHANGE:
    rosinstall_generator desktop_full --rosdistro melodic --deps --tar > melodic-desktop-full.rosinstall
    TO:
    rosinstall_generator ros_base --rosdistro melodic --deps --tar > melodic-base.rosinstall

  2. CHANGE:
    wstool init -j8 src melodic-desktop-full.rosinstall
    TO:
    wstool init -j8 src melodic-base.rosinstall

  3. DELETE:
    pip install -U -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-18.04 wxPython

  4. CHANGE:
    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"
    TO:
    sudo ./install_skip rosdep check --from-paths src --ignore-src | grep python | grep -v wxtool | sed -e "s/^apt\t//g" | sed -z "s/\n/ /g" | sed -e "s/\<python\>/python3/g"
    (check the back quotes in these lines, the markdown is messing it up - basically added | grep -v wxtool to the chain.

Thanks to everyone here, I've now got ros1 running on a Pi using python3.

@yaobinwen
Copy link

yaobinwen commented Jun 24, 2020

Thanks for the instructions! I'm following them and they are helpful! Can I also ask how you figured out the instructions? Did you get them from some other sources? I tried to search in the ROS official website and ROS source code repositories but didn't seem to find them. How did you find the instructions?

@linzha0
Copy link

linzha0 commented Jun 24, 2020

(Moved this from the blog for history preservation purpose)
Two errors were encountered during setting up with this tutorial:

  1. When catkin_make:
File "/usr/lib/python3.6/signal.py", line 47, in signal
TypeError: signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object

This will not affect launching roscore just as you posted before.

  1. When rosrun somepacakge somecode.py:
rosrun topic_demo pytalker.py
Traceback (most recent call last):
File "/root/catkin_ws/src/ROS-Academy-for-Beginners/topic_demo/scripts/pytalker.py", line 3, in <module>
import rospy
File "/root/ros_catkin_ws/install/lib/python3/dist-packages/rospy/__init__.py", line 47, in <module>
from std_msgs.msg import Header
File "/root/ros_catkin_ws/install/lib/python3/dist-packages/std_msgs/msg/__init__.py", line 1, in <module>
from ._Bool import *
File "/root/ros_catkin_ws/install/lib/python3/dist-packages/std_msgs/msg/_Bool.py", line 5, in <module>
import genpy
File "/root/ros_catkin_ws/install/lib/python3/dist-packages/genpy/__init__.py", line 34, in <module>
from . message import Message, SerializationError, DeserializationError, MessageException, struct_I
File "/root/ros_catkin_ws/install/lib/python3/dist-packages/genpy/message.py", line 44, in <module>
import yaml
File "/usr/lib/python3/dist-packages/yaml/__init__.py", line 284
class YAMLObject(metaclass=YAMLObjectMetaclass):
^
SyntaxError: invalid syntax

This is an interesting error.. Python seems to be complaining about the python3's metaclass syntax here. And with the traceback log, ROS is trying to run with python3 here but somehow ended up using python2 when the error happens.

Does anyone have any insight?

@zzh112119, Hi, I have same question with you. Is your problem related to YAMLObject Syntax solved by uninstall python2? which installed accidentally after install libboost?

@graemerae
Copy link

graemerae commented Jun 24, 2020

Thanks for the instructions! I'm following them and they are helpful! Can I also ask how you figured out the instructions? Did you get them from some other sources? I tried to search in the ROS official website and ROS source code repositories but didn't seem to find them. How did you find the instructions?

Trial and Error :-)

(Moved this from the blog for history preservation purpose)
Two errors were encountered during setting up with this tutorial:

  1. When catkin_make:
File "/usr/lib/python3.6/signal.py", line 47, in signal
TypeError: signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object

This will not affect launching roscore just as you posted before.

  1. When rosrun somepacakge somecode.py:
rosrun topic_demo pytalker.py
Traceback (most recent call last):
File "/root/catkin_ws/src/ROS-Academy-for-Beginners/topic_demo/scripts/pytalker.py", line 3, in <module>
import rospy
File "/root/ros_catkin_ws/install/lib/python3/dist-packages/rospy/__init__.py", line 47, in <module>
from std_msgs.msg import Header
File "/root/ros_catkin_ws/install/lib/python3/dist-packages/std_msgs/msg/__init__.py", line 1, in <module>
from ._Bool import *
File "/root/ros_catkin_ws/install/lib/python3/dist-packages/std_msgs/msg/_Bool.py", line 5, in <module>
import genpy
File "/root/ros_catkin_ws/install/lib/python3/dist-packages/genpy/__init__.py", line 34, in <module>
from . message import Message, SerializationError, DeserializationError, MessageException, struct_I
File "/root/ros_catkin_ws/install/lib/python3/dist-packages/genpy/message.py", line 44, in <module>
import yaml
File "/usr/lib/python3/dist-packages/yaml/__init__.py", line 284
class YAMLObject(metaclass=YAMLObjectMetaclass):
^
SyntaxError: invalid syntax

This is an interesting error.. Python seems to be complaining about the python3's metaclass syntax here. And with the traceback log, ROS is trying to run with python3 here but somehow ended up using python2 when the error happens.
Does anyone have any insight?

@zzh112119, Hi, I have same question with you. Is your problem related to YAMLObject Syntax solved by uninstall python2? which installed accidentally after install libboost?

Did you check this? If the head of the file is :
#!/usr/bin/env python

Make sure that it points to python3

Or change it to:
#/usr/bin/python3
(or whatever your path is the executable)

@linzha0
Copy link

linzha0 commented Jun 24, 2020

@graemerae, thanks for your reply, after changing to #!/usr/bin/python3, it's working, cheer!

@Michdo93
Copy link

Michdo93 commented Jun 28, 2020

Hi, I got following error.

Exception ignored in: <bound method BaseEventLoop.del of <_UnixSelectorEventLoop running=False closed=True debug=False>>
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/trollius/base_events.py", line 395, in del
File "/usr/local/lib/python3.6/dist-packages/trollius/unix_events.py", line 65, in close
File "/usr/local/lib/python3.6/dist-packages/trollius/unix_events.py", line 166, in remove_signal_handler
File "/usr/lib/python3.6/signal.py", line 48, in signal
TypeError: signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object

I tried to change this line #/usr/bin/python3 and it doesnt help. Also I tried sudo apt install -y python-empy and other solutions posted here. It doesnt work.

@linzha0
Copy link

linzha0 commented Jun 28, 2020

Hi, I got following error.

Exception ignored in: <bound method BaseEventLoop.del of <_UnixSelectorEventLoop running=False closed=True debug=False>>
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/trollius/base_events.py", line 395, in del
File "/usr/local/lib/python3.6/dist-packages/trollius/unix_events.py", line 65, in close
File "/usr/local/lib/python3.6/dist-packages/trollius/unix_events.py", line 166, in remove_signal_handler
File "/usr/lib/python3.6/signal.py", line 48, in signal
TypeError: signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object

I tried to change this line #/usr/bin/python3 and it doesnt help. Also I tried sudo apt install -y python-empy and other solutions posted here. It doesnt work.

Does roscore and a simple python publisher working? This problem should be fine.

@IndustrialEngStudent
Copy link

IndustrialEngStudent commented Aug 20, 2020

Hi I ran into the following problem:

(base) laurah@laurah-HP-EliteBook-840-G1:~/ros_catkin_ws$ 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"`
Installing python3-psutil
Installing python33-paramiko
E: Unable to locate package python33-paramiko
Installing python33-rosdep-modules
E: Unable to locate package python33-rosdep-modules
Installing python33-coverage
E: Unable to locate package python33-coverage
Installing python3-rospkg
Installing python3-mock
Installing python3-catkin-pkg
Installing python3-matplotlib
Installing python3-numpy
Installing python33-pydot
E: Unable to locate package python33-pydot
Installing python33-pygraphviz
E: Unable to locate package python33-pygraphviz
Installing python33-pycryptodome
E: Unable to locate package python33-pycryptodome
Installing python33-gnupg
E: Unable to locate package python33-gnupg
Installing python3-opencv
Installing python33-empy
E: Unable to locate package python33-empy
Installing python33-defusedxml
E: Unable to locate package python33-defusedxml
Installing python33-nose
E: Unable to locate package python33-nose
Installing python3-opengl

I fixed this with "sudo apt-get install python3-[package]", now I get this when building:

error: option --install-layout not recognized
CMake Error at catkin_generated/safe_execute_install.cmake:4 (message):
  
  execute_process(/home/laurah/ros_catkin_ws/build/catkin/catkin_generated/python_distutils_install.sh)
  returned error code
Call Stack (most recent call first):
  cmake_install.cmake:171 (include)


make: *** [install] Error 1
cd /home/laurah/ros_catkin_ws/build/catkin; catkin build --get-env catkin | catkin env -si  /usr/bin/make install; cd -

...

[build]   Ignored:   33 packages were skipped or are blacklisted.                                                                                                              
[build]   Warnings:  None.                                                                                                                                                     
[build]   Abandoned: 203 packages were abandoned.                                                                                                                              
[build]   Failed:    1 packages failed.                                                                                                                                        
[build] Runtime: 4.0 seconds total.                                                                                                                                            
Exception ignored in: <bound method BaseEventLoop.__del__ of <_UnixSelectorEventLoop running=False closed=True debug=False>>
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/trollius/base_events.py", line 395, in __del__
  File "/usr/local/lib/python3.6/dist-packages/trollius/unix_events.py", line 65, in close
  File "/usr/local/lib/python3.6/dist-packages/trollius/unix_events.py", line 166, in remove_signal_handler
  File "/usr/lib/python3.6/signal.py", line 47, in signal
TypeError: signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object

I know that others experienced the same. I tried the solutions they used, but it does not help in my case.
What am I doing wrong?

@stephjo
Copy link

stephjo commented Oct 1, 2020

[build] Ignored: 33 packages were skipped or are blacklisted.
[build] Warnings: None.
[build] Abandoned: 203 packages were abandoned.
[build] Failed: 1 packages failed.
[build] Runtime: 4.0 seconds total.
Exception ignored in: <bound method BaseEventLoop.del of <_UnixSelectorEventLoop running=False closed=True debug=False>>
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/trollius/base_events.py", line 395, in del
File "/usr/local/lib/python3.6/dist-packages/trollius/unix_events.py", line 65, in close
File "/usr/local/lib/python3.6/dist-packages/trollius/unix_events.py", line 166, in remove_signal_handler
File "/usr/lib/python3.6/signal.py", line 47, in signal
TypeError: signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object

I am getting the same error after following the recommended steps.I am trying install ros melodic on ubuntu 18.04.Please help.

@Ademord
Copy link

Ademord commented Oct 11, 2020

@metalglove if i change your script from melodic to noetic it should work? i will test it today...

@metalglove
Copy link

metalglove commented Oct 11, 2020

@metalglove if i change your script from melodic to noetic it should work? i will test it today...

There is a supported noetic version for Python3.

@Ademord
Copy link

Ademord commented Oct 11, 2020

@metalglove thanks for taking the time to reply on a sunday :) i worked until 6 am yesterday haha!
I am not 100% sure what I did (well, our life), but I did manage to install on a ubuntu20.04 image, python3.8 and ros-noetic without building the same way you did (that's why I had uncertainty about it working).
If you have time maybe to explain to me why this worked compared to your solution I'd highly appreciate it as a learning experience :)

# Dockerfile
(i installed sudo and created a user above...)
ENV ROS_DISTRO=noetic

# install utilities
RUN apt-get install -y vim bash tmux git wget lsb-release lsb-core

# install the python3 libraries 
RUN apt-get install -y python3 python3-dev python3-pip build-essential

# link python -> python3
RUN ln -s /usr/bin/python3 /usr/bin/python

# Same for pip
RUN ln -s /usr/bin/pip3 /usr/bin/pip

# install ROS dependencies
RUN pip install rosdep rospkg rosinstall catkin_tools catkin_pkg

# install python-empy
RUN apt-get install -y python3-empy

# Install ROS
RUN sh -c 'echo "deb http://packages.ros.org/ros/ubuntu `lsb_release -cs` main" > /etc/apt/sources.list.d/ros-latest.list' && \
    apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-key C1CF6E31E6BADE8868B172B4F42ED6FBAB17C654 && \
    apt-get update && \
    apt-get install -y ros-${ROS_DISTRO}-desktop \
    ros-${ROS_DISTRO}-pcl-ros \
    ros-${ROS_DISTRO}-pcl-conversions \
    ros-${ROS_DISTRO}-image-geometry


# initialize catkin build environment
RUN rosdep init

# adjust user
USER $USER

# fix permissions and update dependencies
RUN rosdep fix-permissions && rosdep update

# i  dont know what to name this comment
RUN echo "source /opt/ros/${ROS_DISTRO}/setup.bash" >> ~/.bashrc
RUN /bin/bash -c "source ~/.bashrc"

# setup catkin workspace << this just makes mkdir, catkin_init_workspace and catkin_make, in brief 
ENV CATKIN_WS ${HOME}/catkin_ws
COPY docker/init_workspace.sh ${HOME}
RUN ${HOME}/init_workspace.sh

Also, I am trying to build a docker image with ubuntu20.04, cuda11 (or 10) with cudnn8 (or 7), but all the available images (official) are either ubuntu18 or below with cuda10, cudnn7, and the ubuntu20 ones have only cuda11 and the package for cudnn8 do not exist yet.. ugh!

@Dhagash4
Copy link

Dhagash4 commented Oct 30, 2020

Everything worked great until I tried to build it!

[build] Summary: 0 of 204 packages succeeded.
[build] Ignored: 33 packages were skipped or are blacklisted.
[build] Warnings: None.
[build] Abandoned: 203 packages were abandoned.
[build] Failed: 1 packages failed.
[build] Runtime: 2.7 seconds total.
Exception ignored in: <bound method BaseEventLoop.del of <_UnixSelectorEventLoop running=False closed=True debug=False>>
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/trollius/base_events.py", line 395, in del
File "/usr/local/lib/python3.6/dist-packages/trollius/unix_events.py", line 65, in close
File "/usr/local/lib/python3.6/dist-packages/trollius/unix_events.py", line 166, in remove_signal_handler
File "/usr/lib/python3.6/signal.py", line 47, in signal
TypeError: signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object
What could have happened? this is on a fresh install of ubuntu.
Thanks!

I am facing same problem any solution that worked I followed all the steps

@Balaji-mg
Copy link

Balaji-mg commented Nov 17, 2020

Errors << compressed_image_transport:make /home/internrobot/ros_catkin_ws/logs/compressed_image_transport/build.make.000.log
/home/internrobot/ros_catkin_ws/src/image_transport_plugins/compressed_image_transport/src/compressed_publisher.cpp: In member function ‘virtual void compressed_image_transport::CompressedPublisher::publish(const Image&, const PublishFn&) const’:
/home/internrobot/ros_catkin_ws/src/image_transport_plugins/compressed_image_transport/src/compressed_publisher.cpp💯19: error: ‘CV_IMWRITE_JPEG_QUALITY’ was not declared in this scope
params[0] = CV_IMWRITE_JPEG_QUALITY;
^~~~~~~~~~~~~~~~~~~~~~~
/home/internrobot/ros_catkin_ws/src/image_transport_plugins/compressed_image_transport/src/compressed_publisher.cpp💯19: note: suggested alternative: ‘CV_WRITE_SEQ_ELEM’
params[0] = CV_IMWRITE_JPEG_QUALITY;
^~~~~~~~~~~~~~~~~~~~~~~
CV_WRITE_SEQ_ELEM
/home/internrobot/ros_catkin_ws/src/image_transport_plugins/compressed_image_transport/src/compressed_publisher.cpp:157:19: error: ‘CV_IMWRITE_PNG_COMPRESSION’ was not declared in this scope
params[0] = CV_IMWRITE_PNG_COMPRESSION;
^~~~~~~~~~~~~~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/compressed_image_transport.dir/src/compressed_publisher.cpp.o] Error 1
make[2]: *** Waiting for unfinished jobs....
make[1]: *** [CMakeFiles/compressed_image_transport.dir/all] Error 2
make: *** [all] Error 2
cd /home/internrobot/ros_catkin_ws/build/compressed_image_transport; catkin build --get-env compressed_image_transport | catkin env -si /usr/bin/make --jobserver-fds=3,4 -j; cd -
...........................................................................................................................................................................................................
Failed << compressed_image_transport:make [ Exited with code 2 ]
Failed <<< compressed_image_transport [ 17.1 seconds ]
Abandoned <<< image_view [ Unrelated job failed ]
Abandoned <<< theora_image_transport [ Unrelated job failed ]
Abandoned <<< rqt_msg [ Unrelated job failed ]
Abandoned <<< rqt_reconfigure [ Unrelated job failed ]
Abandoned <<< rqt_launch [ Unrelated job failed ]
Abandoned <<< rqt_bag_plugins [ Unrelated job failed ]
Abandoned <<< rqt_tf_tree [ Unrelated job failed ]
Abandoned <<< depth_image_proc [ Unrelated job failed ]
Abandoned <<< tf [ Unrelated job failed ]
Abandoned <<< tf2_geometry_msgs [ Unrelated job failed ]
Abandoned <<< tf2_kdl [ Unrelated job failed ]
Abandoned <<< turtle_tf2 [ Unrelated job failed ]
Abandoned <<< position_controllers [ Unrelated job failed ]
Abandoned <<< rqt_action [ Unrelated job failed ]
Abandoned <<< rqt_nav_view [ Unrelated job failed ]
Abandoned <<< rqt_pose_view [ Unrelated job failed ]
Abandoned <<< rqt_robot_dashboard [ Unrelated job failed ]
Abandoned <<< rqt_srv [ Unrelated job failed ]
Abandoned <<< urdf_sim_tutorial [ Unrelated job failed ]
Abandoned <<< diagnostic_common_diagnostics [ Unrelated job failed ]
Abandoned <<< image_publisher [ Unrelated job failed ]
Abandoned <<< stereo_image_proc [ Unrelated job failed ]
Abandoned <<< gazebo_ros [ Unrelated job failed ]
Abandoned <<< interactive_markers [ Unrelated job failed ]
Abandoned <<< interactive_marker_tutorials [ Unrelated job failed ]
Abandoned <<< laser_geometry [ Unrelated job failed ]
Abandoned <<< laser_assembler [ Unrelated job failed ]
Abandoned <<< laser_filters [ Unrelated job failed ]
Abandoned <<< pcl_ros [ Unrelated job failed ]
Abandoned <<< stage_ros [ Unrelated job failed ]
Abandoned <<< image_rotate [ Unrelated job failed ]
Abandoned <<< tf_conversions [ Unrelated job failed ]
Abandoned <<< turtle_tf [ Unrelated job failed ]
Abandoned <<< gazebo_plugins [ Unrelated job failed ]
Abandoned <<< gazebo_ros_control [ Unrelated job failed ]
Abandoned <<< robot_state_publisher [ Unrelated job failed ]
Abandoned <<< rviz [ Unrelated job failed ]
Abandoned <<< rviz_python_tutorial [ Unrelated job failed ]
Abandoned <<< urdf_tutorial [ Unrelated job failed ]
Abandoned <<< diff_drive_controller [ Unrelated job failed ]
Finished <<< polled_camera [ 20.7 seconds ]
Finished <<< camera_info_manager [ 26.8 seconds ]


Warnings << rqt_image_view:install /home/internrobot/ros_catkin_ws/logs/rqt_image_view/build.install.000.log
package init file 'src/rqt_image_view/init.py' not found (or not a regular file)
package init file 'src/rqt_image_view/init.py' not found (or not a regular file)
warning: install_lib: '/home/internrobot/ros_catkin_ws/build/rqt_image_view/lib' does not exist -- no Python modules to install

cd /home/internrobot/ros_catkin_ws/build/rqt_image_view; catkin build --get-env rqt_image_view | catkin env -si /usr/bin/make install; cd -
...........................................................................................................................................................................................................
Finished <<< rqt_image_view [ 16.1 seconds ]


Errors << compressed_depth_image_transport:make /home/internrobot/ros_catkin_ws/logs/compressed_depth_image_transport/build.make.000.log
/home/internrobot/ros_catkin_ws/src/image_transport_plugins/compressed_depth_image_transport/src/codec.cpp: In function ‘sensor_msgs::Image_<std::allocator >::Ptr compressed_depth_image_transport::decodeCompressedDepthImage(const CompressedImage&)’:
/home/internrobot/ros_catkin_ws/src/image_transport_plugins/compressed_depth_image_transport/src/codec.cpp:138:49: error: ‘CV_LOAD_IMAGE_UNCHANGED’ was not declared in this scope
cv_ptr->image = cv::imdecode(imageData, CV_LOAD_IMAGE_UNCHANGED);
^~~~~~~~~~~~~~~~~~~~~~~
make[2]: *** [CMakeFiles/compressed_depth_image_transport.dir/src/codec.cpp.o] Error 1
make[1]: *** [CMakeFiles/compressed_depth_image_transport.dir/all] Error 2
make: *** [all] Error 2
cd /home/internrobot/ros_catkin_ws/build/compressed_depth_image_transport; catkin build --get-env compressed_depth_image_transport | catkin env -si /usr/bin/make --jobserver-fds=3,4 -j; cd -
...........................................................................................................................................................................................................
Failed << compressed_depth_image_transport:make [ Exited with code 2 ]
Failed <<< compressed_depth_image_transport [ 25.8 seconds ]
Finished <<< image_proc [ 31.2 seconds ]
[build] Summary: 162 of 204 packages succeeded.
[build] Ignored: 33 packages were skipped or are blacklisted.
[build] Warnings: 10 packages succeeded with warnings.
[build] Abandoned: 40 packages were abandoned.
[build] Failed: 2 packages failed.
[build] Runtime: 6 minutes and 51.6 seconds total.
[build] Note: Workspace packages have changed, please re-source setup files to use them.
Exception ignored in: <bound method BaseEventLoop.del of <_UnixSelectorEventLoop running=False closed=True debug=False>>
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/trollius/base_events.py", line 395, in del
File "/usr/local/lib/python3.6/dist-packages/trollius/unix_events.py", line 65, in close
File "/usr/local/lib/python3.6/dist-packages/trollius/unix_events.py", line 166, in remove_signal_handler
File "/usr/lib/python3.6/signal.py", line 47, in signal
TypeError: signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object

I am getting these issues, I followed the same steps listed in https://www.miguelalonsojr.com/blog/robotics/ros/python3/2019/08/20/ros-melodic-python-3-build.html

@iamrobusto
Copy link

iamrobusto commented Nov 26, 2020

Does this setup mean that all new ros packages (e.g my own) need to be installed in the build workspace (ros_catkin_ws)?

@gvnwltrs
Copy link

gvnwltrs commented Dec 12, 2020

Unfortunately I couldn't get this python3 configuration to work for me when I was experimenting with this. Having this issue as well:

Exception ignored in: <bound method BaseEventLoop.del of <_UnixSelectorEventLoop running=False closed=True debug=False>>
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/trollius/base_events.py", line 395, in del
File "/usr/local/lib/python3.6/dist-packages/trollius/unix_events.py", line 65, in close
File "/usr/local/lib/python3.6/dist-packages/trollius/unix_events.py", line 166, in remove_signal_handler
File "/usr/lib/python3.6/signal.py", line 47, in signal
TypeError: signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object

What would be the best way to revert the changes made by 'gistfile1.txt' to get back to using Python2.7 with catkin build?

@gvnwltrs
Copy link

gvnwltrs commented Dec 13, 2020

Unfortunately I couldn't get this python3 configuration to work for me when I was experimenting with this. Having this issue as well:

Exception ignored in: <bound method BaseEventLoop.del of <_UnixSelectorEventLoop running=False closed=True debug=False>>
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/trollius/base_events.py", line 395, in del
File "/usr/local/lib/python3.6/dist-packages/trollius/unix_events.py", line 65, in close
File "/usr/local/lib/python3.6/dist-packages/trollius/unix_events.py", line 166, in remove_signal_handler
File "/usr/lib/python3.6/signal.py", line 47, in signal
TypeError: signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object

What would be the best way to revert the changes made by 'gistfile1.txt' to get back to using Python2.7 with catkin build?

UPDATE:

Never-mind. For my particular situation 'catkin_tools' was not completed uninstalled all the way, so had to go into '/usr/local/bin' and manually delete the catkin related binaries as well as as the ros binaries then re-installed ros-melodic and python-catkin-tools and I was back up and running with my old setup using Python2.7.

@MBaranPeker
Copy link

MBaranPeker commented Dec 21, 2020

hi @metalglove, I have followed ur way and succesfully installed. after using the source " source ~/ros_catkin_ws/install/setup.bash" i can use roscore and it works without ant error. But I have a question how can i install moveit for ros melodic. Because whenever i try it gives error it can not locate the file. even if i use source before installing. What I am doing wrong ?

Example I open new terminal:

source ~/ros_catkin_ws/install/setup.bash
sudo apt install ros-melodic-moveit

and here is the error:

E: Unable to locate package ros-melodic-moveit

@yijionglin
Copy link

yijionglin commented Jan 16, 2021

hi @metalglove, I have followed ur way and succesfully installed. after using the source " source ~/ros_catkin_ws/install/setup.bash" i can use roscore and it works without ant error. But I have a question how can i install moveit for ros melodic. Because whenever i try it gives error it can not locate the file. even if i use source before installing. What I am doing wrong ?

Example I open new terminal:

source ~/ros_catkin_ws/install/setup.bash
sudo apt install ros-melodic-moveit

and here is the error:

E: Unable to locate package ros-melodic-moveit

HI @MBaranPeker,

You cannot just use sudo apt install ros-melodic-moveit since this is a binary version with Python 2.

You should download the source code and then build it with python 3. Here is the guide could probably help you.

Let me know if this works for you.

Cheers,

@MBaranPeker
Copy link

MBaranPeker commented Jan 25, 2021

Hi, @YijiongLin. Thank you so much. It is working now.

@shandilya1998
Copy link

shandilya1998 commented Feb 16, 2021

Hey! I was able to install ROS, but am not able to import rospy. I am trying to install ROS on Google Colab and the following were the commands that I used to install ros-base:

!sudo apt update
!sudo -H pip3 install rosdep rospkg rosinstall_generator rosinstall wstool vcstools
!git clone https://github.com/catkin/catkin_tools.git && cd catkin_tools && pip3 install -r requirements.txt --upgrade && python setup.py install --record install_manifest.txt
!apt-get install python-catkin-pkg
!apt-get install python3-empy
!apt-get update && apt-get install --only-upgrade python-catkin-pkg
!sudo rosdep init
!rosdep update
!sudo rosdep fix-permissions
!rosdep update
!git clone https://github.com/shandilya1998/CPGController
import os
os.chdir('/content/CPGController/src/simulations/ws')
!catkin config --init -DCMAKE_BUILD_TYPE=Release --blacklist rqt_rviz rviz_plugin_tutorials librviz_tutorial gazebo moveit --install
!rosinstall_generator ros_base --rosdistro melodic --deps --tar > melodic-ros-base.rosinstall
!wstool init -j8 src melodic-ros-base.rosinstall
os.environ['ROS_PYTHON_VERSION'] = '3'
!pip3 install -U -f https://extras.wxpython.org/wxPython4/extras/linux/gtk3/ubuntu-18.04 wxPython
!printf -- '#/bin/bash\n#Check whether root\nif [ $(whoami) != root ]; then\necho You must be root or use sudo to install packages.\nreturn\nfi\n#Call apt-get for each package\nfor pkg in "$@"\ndo\necho "Installing $pkg"\nsudo apt-get -my install $pkg >> install.log\ndone\n' > install_skip
!chmod +x install_skip
!sudo ./install_skip rosdep check --from-paths src --ignore-src | grep python | grep -v wxtool | 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' {} +
!catkin clean -y
!catkin build
os.environ['PYTHONPATH'] += ':/content/CPGController/src/simulations/ws/install/lib/python3/dist-packages:/usr/lib/python3/dist-packages'
!source install/setup.bash
os.chdir('/content/CPGController/src')
os.environ['ROS_PACKAGE_PATH']='/content/CPGController/src/simulations/ws/src'

When I do pip list, rospy shows up in the list. But when I try to import rospy, I get the following error:

---------------------------------------------------------------------------

ModuleNotFoundError                       Traceback (most recent call last)

<ipython-input-8-fb60b5b51009> in <module>()
----> 1 import rospy

ModuleNotFoundError: No module named 'rospy'


---------------------------------------------------------------------------
NOTE: If your import is failing due to a missing package, you can
manually install dependencies using either !pip or !apt.

To view examples of installing some common dependencies, click the
"Open Examples" button below.
---------------------------------------------------------------------------

Also I can import rospkg in python, but none of the other ros modules. Any idea what could be the problem?

@XV25
Copy link

XV25 commented Feb 26, 2021

Hi,

Let me add a small remark for all the people (including me) who have encountered problems building ROS Melodic with Python 3. It is possible to make ROS Melodic work with Python 3 via an "apt" command, without having to build all the ROS packages with Python 3. The procedure is detailed here : https://dhanoopbhaskar.com/blog/2020-05-07-working-with-python-3-in-ros-kinetic-or-melodic/ .
I have not yet completely checked the installation, but thanks to this one the ROS publisher / subscriber seems to be operational with rospy.
The only drawback is that it is necessary to reinstall all ROS Melodic packages; but it seems less risky than trying to build all ROS packages with Python 3.

Regards,

XV25

@akshayacharya97
Copy link

akshayacharya97 commented Aug 13, 2021

I am getting the following error when i catkin_make in the end. I have followed all the steps as shown. I am using jetson xavier nx iwth ubuntu 18

Profile: default
Extending: [env] /home/akshay/catkin_ws/devel:/opt/ros/melodic
Workspace: /home/akshay/ros_catkin_ws

Build Space: [exists] /home/akshay/ros_catkin_ws/build
Devel Space: [exists] /home/akshay/ros_catkin_ws/devel
Install Space: [missing] /home/akshay/ros_catkin_ws/install
Log Space: [exists] /home/akshay/ros_catkin_ws/logs
Source Space: [exists] /home/akshay/ros_catkin_ws/src
DESTDIR: [unused] None

Devel Space Layout: linked
Install Space Layout: merged

Additional CMake Args: -DCMAKE_BUILD_TYPE=Release
Additional Make Args: None
Additional catkin Make Args: None
Internal Make Job Server: True
Cache Job Environments: False

Whitelisted Packages: None
Blacklisted Packages: rqt_rviz rviz_plugin_tutorials librviz_tutorial

Workspace configuration appears valid.

[build] Found '237' packages in 0.0 seconds.
Warning: generated devel space setup files have been deleted.
Starting >>> catkin


Errors << catkin:cmake /home/akshay/ros_catkin_ws/logs/catkin/build.cmake.001.log
CMake Error at /home/akshay/ros_catkin_ws/src/catkin/cmake/empy.cmake:30 (message):
Unable to find either executable 'empy' or Python module 'em'... try
installing the package 'python-empy'
Call Stack (most recent call first):
cmake/all.cmake:164 (include)
CMakeLists.txt:8 (include)

cd /home/akshay/ros_catkin_ws/build/catkin; catkin build --get-env catkin | catkin env -si /usr/bin/cmake /home/akshay/ros_catkin_ws/src/catkin --no-warn-unused-cli -DCATKIN_DEVEL_PREFIX=/home/akshay/ros_catkin_ws/devel/.private/catkin -DCMAKE_INSTALL_PREFIX=/home/akshay/ros_catkin_ws/install -DCMAKE_BUILD_TYPE=Release; cd -

...............................................................................
Failed << catkin:cmake [ Exited with code 1 ]
Failed <<< catkin [ 0.6 seconds ]
Abandoned <<< genmsg [ Unrelated job failed ]
Abandoned <<< gencpp [ Unrelated job failed ]
Abandoned <<< geneus [ Unrelated job failed ]
Abandoned <<< genlisp [ Unrelated job failed ]
Abandoned <<< gennodejs [ Unrelated job failed ]
Abandoned <<< genpy [ Unrelated job failed ]
Abandoned <<< bond_core [ Unrelated job failed ]
Abandoned <<< cmake_modules [ Unrelated job failed ]
Abandoned <<< class_loader [ Unrelated job failed ]
Abandoned <<< common_msgs [ Unrelated job failed ]
Abandoned <<< common_tutorials [ Unrelated job failed ]
Abandoned <<< cpp_common [ Unrelated job failed ]
Abandoned <<< desktop [ Unrelated job failed ]
Abandoned <<< desktop_full [ Unrelated job failed ]
Abandoned <<< diagnostics [ Unrelated job failed ]
Abandoned <<< executive_smach [ Unrelated job failed ]
Abandoned <<< gazebo_dev [ Unrelated job failed ]
Abandoned <<< gazebo_ros_pkgs [ Unrelated job failed ]
Abandoned <<< geometry [ Unrelated job failed ]
Abandoned <<< geometry_tutorials [ Unrelated job failed ]
Abandoned <<< gl_dependency [ Unrelated job failed ]
Abandoned <<< image_common [ Unrelated job failed ]
Abandoned <<< image_pipeline [ Unrelated job failed ]
Abandoned <<< image_transport_plugins [ Unrelated job failed ]
Abandoned <<< laser_pipeline [ Unrelated job failed ]
Abandoned <<< media_export [ Unrelated job failed ]
Abandoned <<< message_generation [ Unrelated job failed ]
Abandoned <<< message_runtime [ Unrelated job failed ]
Abandoned <<< mk [ Unrelated job failed ]
Abandoned <<< nodelet_core [ Unrelated job failed ]
Abandoned <<< orocos_kdl [ Unrelated job failed ]
Abandoned <<< perception [ Unrelated job failed ]
Abandoned <<< perception_pcl [ Unrelated job failed ]
Abandoned <<< python_orocos_kdl [ Unrelated job failed ]
Abandoned <<< qt_dotgraph [ Unrelated job failed ]
Abandoned <<< qt_gui [ Unrelated job failed ]
Abandoned <<< qt_gui_py_common [ Unrelated job failed ]
Abandoned <<< qwt_dependency [ Unrelated job failed ]
Abandoned <<< robot [ Unrelated job failed ]
Abandoned <<< ros [ Unrelated job failed ]
Abandoned <<< ros_base [ Unrelated job failed ]
Abandoned <<< ros_comm [ Unrelated job failed ]
Abandoned <<< ros_core [ Unrelated job failed ]
Abandoned <<< ros_environment [ Unrelated job failed ]
Abandoned <<< ros_tutorials [ Unrelated job failed ]
Abandoned <<< rosbag_migration_rule [ Unrelated job failed ]
Abandoned <<< rosbash [ Unrelated job failed ]
Abandoned <<< rosboost_cfg [ Unrelated job failed ]
Abandoned <<< rosbuild [ Unrelated job failed ]
Abandoned <<< rosclean [ Unrelated job failed ]
Abandoned <<< roscpp_core [ Unrelated job failed ]
Abandoned <<< roscpp_traits [ Unrelated job failed ]
Abandoned <<< roscreate [ Unrelated job failed ]
Abandoned <<< rosgraph [ Unrelated job failed ]
Abandoned <<< roslang [ Unrelated job failed ]
Abandoned <<< roslint [ Unrelated job failed ]
Abandoned <<< roslisp [ Unrelated job failed ]
Abandoned <<< rosmake [ Unrelated job failed ]
Abandoned <<< rosmaster [ Unrelated job failed ]
Abandoned <<< rospack [ Unrelated job failed ]
Abandoned <<< roslib [ Unrelated job failed ]
Abandoned <<< rosparam [ Unrelated job failed ]
Abandoned <<< rospy [ Unrelated job failed ]
Abandoned <<< rosservice [ Unrelated job failed ]
Abandoned <<< rostime [ Unrelated job failed ]
Abandoned <<< roscpp_serialization [ Unrelated job failed ]
Abandoned <<< python_qt_binding [ Unrelated job failed ]
Abandoned <<< roslaunch [ Unrelated job failed ]
Abandoned <<< rosunit [ Unrelated job failed ]
Abandoned <<< angles [ Unrelated job failed ]
Abandoned <<< rosconsole [ Unrelated job failed ]
Abandoned <<< pluginlib [ Unrelated job failed ]
Abandoned <<< qt_gui_cpp [ Unrelated job failed ]
Abandoned <<< resource_retriever [ Unrelated job failed ]
Abandoned <<< rosconsole_bridge [ Unrelated job failed ]
Abandoned <<< roslz4 [ Unrelated job failed ]
Abandoned <<< rostest [ Unrelated job failed ]
Abandoned <<< rqt_action [ Unrelated job failed ]
Abandoned <<< rqt_bag [ Unrelated job failed ]
Abandoned <<< rqt_bag_plugins [ Unrelated job failed ]
Abandoned <<< rqt_common_plugins [ Unrelated job failed ]
Abandoned <<< rqt_console [ Unrelated job failed ]
Abandoned <<< rqt_dep [ Unrelated job failed ]
Abandoned <<< rqt_graph [ Unrelated job failed ]
Abandoned <<< rqt_gui [ Unrelated job failed ]
Abandoned <<< rqt_logger_level [ Unrelated job failed ]
Abandoned <<< rqt_moveit [ Unrelated job failed ]
Abandoned <<< rqt_msg [ Unrelated job failed ]
Abandoned <<< rqt_nav_view [ Unrelated job failed ]
Abandoned <<< rqt_plot [ Unrelated job failed ]
Abandoned <<< rqt_pose_view [ Unrelated job failed ]
Abandoned <<< rqt_publisher [ Unrelated job failed ]
Abandoned <<< rqt_py_console [ Unrelated job failed ]
Abandoned <<< rqt_robot_dashboard [ Unrelated job failed ]
Abandoned <<< rqt_robot_monitor [ Unrelated job failed ]
Abandoned <<< rqt_robot_plugins [ Unrelated job failed ]
Abandoned <<< rqt_robot_steering [ Unrelated job failed ]
Abandoned <<< rqt_runtime_monitor [ Unrelated job failed ]
Abandoned <<< rqt_service_caller [ Unrelated job failed ]
Abandoned <<< rqt_shell [ Unrelated job failed ]
Abandoned <<< rqt_srv [ Unrelated job failed ]
Abandoned <<< rqt_tf_tree [ Unrelated job failed ]
Abandoned <<< rqt_top [ Unrelated job failed ]
Abandoned <<< rqt_topic [ Unrelated job failed ]
Abandoned <<< rqt_web [ Unrelated job failed ]
Abandoned <<< simulators [ Unrelated job failed ]
Abandoned <<< smach [ Unrelated job failed ]
Abandoned <<< smclib [ Unrelated job failed ]
Abandoned <<< stage [ Unrelated job failed ]
Abandoned <<< std_msgs [ Unrelated job failed ]
Abandoned <<< actionlib_msgs [ Unrelated job failed ]
Abandoned <<< bond [ Unrelated job failed ]
Abandoned <<< controller_manager_msgs [ Unrelated job failed ]
Abandoned <<< diagnostic_msgs [ Unrelated job failed ]
Abandoned <<< geometry_msgs [ Unrelated job failed ]
Abandoned <<< eigen_conversions [ Unrelated job failed ]
Abandoned <<< kdl_conversions [ Unrelated job failed ]
Abandoned <<< nav_msgs [ Unrelated job failed ]
Abandoned <<< rosgraph_msgs [ Unrelated job failed ]
Abandoned <<< rqt_py_common [ Unrelated job failed ]
Abandoned <<< shape_msgs [ Unrelated job failed ]
Abandoned <<< smach_msgs [ Unrelated job failed ]
Abandoned <<< std_srvs [ Unrelated job failed ]
Abandoned <<< tf2_msgs [ Unrelated job failed ]
Abandoned <<< tf2 [ Unrelated job failed ]
Abandoned <<< tf2_eigen [ Unrelated job failed ]
Abandoned <<< trajectory_msgs [ Unrelated job failed ]
Abandoned <<< control_msgs [ Unrelated job failed ]
Abandoned <<< urdf_parser_plugin [ Unrelated job failed ]
Abandoned <<< urdf_sim_tutorial [ Unrelated job failed ]
Abandoned <<< urdfdom_py [ Unrelated job failed ]
Abandoned <<< vision_opencv [ Unrelated job failed ]
Abandoned <<< visualization_msgs [ Unrelated job failed ]
Abandoned <<< visualization_tutorials [ Unrelated job failed ]
Abandoned <<< viz [ Unrelated job failed ]
Abandoned <<< webkit_dependency [ Unrelated job failed ]
Abandoned <<< xmlrpcpp [ Unrelated job failed ]
Abandoned <<< roscpp [ Unrelated job failed ]
Abandoned <<< bondcpp [ Unrelated job failed ]
Abandoned <<< bondpy [ Unrelated job failed ]
Abandoned <<< hardware_interface [ Unrelated job failed ]
Abandoned <<< controller_interface [ Unrelated job failed ]
Abandoned <<< nodelet [ Unrelated job failed ]
Abandoned <<< nodelet_tutorial_math [ Unrelated job failed ]
Abandoned <<< pluginlib_tutorials [ Unrelated job failed ]
Abandoned <<< roscpp_tutorials [ Unrelated job failed ]
Abandoned <<< rosout [ Unrelated job failed ]
Abandoned <<< camera_calibration [ Unrelated job failed ]
Abandoned <<< diagnostic_aggregator [ Unrelated job failed ]
Abandoned <<< diagnostic_updater [ Unrelated job failed ]
Abandoned <<< diagnostic_common_diagnostics [ Unrelated job failed ]
Abandoned <<< dynamic_reconfigure [ Unrelated job failed ]
Abandoned <<< filters [ Unrelated job failed ]
Abandoned <<< joint_state_publisher [ Unrelated job failed ]
Abandoned <<< message_filters [ Unrelated job failed ]
Abandoned <<< rosbag_storage [ Unrelated job failed ]
Abandoned <<< rosmsg [ Unrelated job failed ]
Abandoned <<< rosnode [ Unrelated job failed ]
Abandoned <<< rospy_tutorials [ Unrelated job failed ]
Abandoned <<< rostopic [ Unrelated job failed ]
Abandoned <<< rqt_gui_cpp [ Unrelated job failed ]
Abandoned <<< rqt_gui_py [ Unrelated job failed ]
Abandoned <<< rqt_reconfigure [ Unrelated job failed ]
Abandoned <<< self_test [ Unrelated job failed ]
Abandoned <<< smach_ros [ Unrelated job failed ]
Abandoned <<< tf2_py [ Unrelated job failed ]
Abandoned <<< topic_tools [ Unrelated job failed ]
Abandoned <<< rosbag [ Unrelated job failed ]
Abandoned <<< actionlib [ Unrelated job failed ]
Abandoned <<< actionlib_tutorials [ Unrelated job failed ]
Abandoned <<< controller_manager [ Unrelated job failed ]
Abandoned <<< diagnostic_analysis [ Unrelated job failed ]
Abandoned <<< nodelet_topic_tools [ Unrelated job failed ]
Abandoned <<< realtime_tools [ Unrelated job failed ]
Abandoned <<< control_toolbox [ Unrelated job failed ]
Abandoned <<< forward_command_controller [ Unrelated job failed ]
Abandoned <<< position_controllers [ Unrelated job failed ]
Abandoned <<< roswtf [ Unrelated job failed ]
Abandoned <<< rqt_launch [ Unrelated job failed ]
Abandoned <<< sensor_msgs [ Unrelated job failed ]
Abandoned <<< camera_calibration_parsers [ Unrelated job failed ]
Abandoned <<< cv_bridge [ Unrelated job failed ]
Abandoned <<< gazebo_msgs [ Unrelated job failed ]
Abandoned <<< image_geometry [ Unrelated job failed ]
Abandoned <<< image_transport [ Unrelated job failed ]
Abandoned <<< camera_info_manager [ Unrelated job failed ]
Abandoned <<< compressed_depth_image_transport [ Unrelated job failed ]
Abandoned <<< compressed_image_transport [ Unrelated job failed ]
Abandoned <<< image_proc [ Unrelated job failed ]
Abandoned <<< image_publisher [ Unrelated job failed ]
Abandoned <<< joint_state_controller [ Unrelated job failed ]
Abandoned <<< map_msgs [ Unrelated job failed ]
Abandoned <<< pcl_msgs [ Unrelated job failed ]
Abandoned <<< pcl_conversions [ Unrelated job failed ]
Abandoned <<< polled_camera [ Unrelated job failed ]
Abandoned <<< rqt_image_view [ Unrelated job failed ]
Abandoned <<< stereo_msgs [ Unrelated job failed ]
Abandoned <<< image_view [ Unrelated job failed ]
Abandoned <<< stereo_image_proc [ Unrelated job failed ]
Abandoned <<< tf2_ros [ Unrelated job failed ]
Abandoned <<< depth_image_proc [ Unrelated job failed ]
Abandoned <<< tf [ Unrelated job failed ]
Abandoned <<< gazebo_ros [ Unrelated job failed ]
Abandoned <<< interactive_markers [ Unrelated job failed ]
Abandoned <<< interactive_marker_tutorials [ Unrelated job failed ]
Abandoned <<< pcl_ros [ Unrelated job failed ]
Abandoned <<< stage_ros [ Unrelated job failed ]
Abandoned <<< tf2_geometry_msgs [ Unrelated job failed ]
Abandoned <<< image_rotate [ Unrelated job failed ]
Abandoned <<< laser_geometry [ Unrelated job failed ]
Abandoned <<< laser_assembler [ Unrelated job failed ]
Abandoned <<< laser_filters [ Unrelated job failed ]
Abandoned <<< tf2_kdl [ Unrelated job failed ]
Abandoned <<< tf_conversions [ Unrelated job failed ]
Abandoned <<< theora_image_transport [ Unrelated job failed ]
Abandoned <<< transmission_interface [ Unrelated job failed ]
Abandoned <<< turtlesim [ Unrelated job failed ]
Abandoned <<< turtle_actionlib [ Unrelated job failed ]
Abandoned <<< turtle_tf [ Unrelated job failed ]
Abandoned <<< turtle_tf2 [ Unrelated job failed ]
Abandoned <<< urdf [ Unrelated job failed ]
Abandoned <<< gazebo_plugins [ Unrelated job failed ]
Abandoned <<< joint_limits_interface [ Unrelated job failed ]
Abandoned <<< gazebo_ros_control [ Unrelated job failed ]
Abandoned <<< kdl_parser [ Unrelated job failed ]
Abandoned <<< kdl_parser_py [ Unrelated job failed ]
Abandoned <<< robot_state_publisher [ Unrelated job failed ]
Abandoned <<< rviz [ Unrelated job failed ]
Abandoned <<< rviz_python_tutorial [ Unrelated job failed ]
Abandoned <<< urdf_tutorial [ Unrelated job failed ]
Abandoned <<< visualization_marker_tutorials [ Unrelated job failed ]
Abandoned <<< xacro [ Unrelated job failed ]
Abandoned <<< diff_drive_controller [ Unrelated job failed ]
[build] Summary: 0 of 234 packages succeeded.
[build] Ignored: 3 packages were skipped or are blacklisted.
[build] Warnings: None.
[build] Abandoned: 233 packages were abandoned.
[build] Failed: 1 packages failed.
[build] Runtime: 8.2 seconds total.

@Akashleena
Copy link

Akashleena commented Sep 22, 2021

Thanks @drmaj this worked for me

@Trushantadeshara
Copy link

Trushantadeshara commented Mar 2, 2022

Hello, I was successfully able to install ROS melodic with python3 on Jetson Nano. But there is one issue I am facing. So, I added
source ~/ros_catkin_ws/install/setup.bash in my bashrc file. Now all of my project packages are in another catkin workspace called pre_production. The issue is I am able to build pre_production workspace with ROS but now even I source devel/setup.bash, it is now taking that and I am not able to run any launch files for nodes from pre_production workspace. Any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment