How do you use Python3 and its libraries with ROS Melodic (researched)?
Hi, I'm a total ROS newbie and I'm looking for help with integrating SPADE multi-agent Python library (3.6 and up) with ROS Melodic (Ubuntu 18.04). I'm really desperate right now because I was looking for many different anwsers how to do such a thing. This is a precise description of what I did and with many many different attempts before:
Creating the main package:
- I create folders
catkin_ws/src
and run the commandcatkin_make
incatkin_ws
to create a workspace. - I create the first package named
spade_test
in which the main .py files will be located, I usecatkin_create_pkg spade_test std_msgs rospy
in thesrc
folder. - Every time I change something significant, I run
catkin_make
and. ~/catkin_ws/devel/setup.bash
commands. - I add
<build_depend>message_generation</build_depend>
and<exec_depend>message_runtime</exec_depend>
topackage.xml
file andmessage_generation
infind_package
section andCATKIN_DEPENDS message_runtime
incatkin_package
section ofCMakeLists.txt
file. I also uncomment thegenerate_messages
section (don't think anything in this step is essential). - I add 2 files
talker.py
andlistener.py
to thespade_test
folder, the same code as in this tutorial. - I'm using the
chmod + x filename.py
command to make these work as executable files.
Creating package with a library inside:
I create the
spade
package by using thecatkin_create_pkg spade std_msgs rospy
command in thesrc
folder.In the
package.xml
file in the<version>
tag, I change it to3.1.2
, while in theCMakeLists.txt
file I uncomment thecatkin_python_setup()
line.I git clone everything from the SPADE repository to the
spade
folder (setup.py
file included).In
spade_test
package'spackage.xml
file I add 3 lines:<build_depend>spade</build_depend>
,<build_export_depend>spade</build_export_depend>
and<exec_depend>spade</exec_depend>
. In itsCMakeLists.txt
I addspade
tofind_package
section.After using
catkin_make
and. ~/catkin_ws/devel/setup.bash
commands, thetalker.py
andlistener.py
files work fine after usingrosrun spade_test talker.py
etc.I added
from spade.agent import Agent
to test it if the library works properly and sadly it doesn't, the error occured:
Error
Traceback (most recent call last):
File "/home/my_name/catkin_ws/src/spade_test/talker.py", line 6, in <module>
from spade.agent import Agent
File "/home/my_name/catkin_ws/devel/lib/python2.7/dist-packages/spade/__init__.py", line 35, in <module>
exec(__fh.read())
File "<string>", line 3, in <module>
File "/home/my_name/catkin_ws/src/spade/spade/agent.py", line 86
async def _async_start(self, auto_register=True):
^
SyntaxError: invalid syntax
It's definitely related to the wrong version of Python my ROS is using (2.7) and I was looking everywhere to change it (even some answers from this place) but sadly nothing has helped. I also created another catkin workspace with catkin build --cmake-args -DPYTHON_VERSION=3.6
command instead of catkin_make
with the exact same result (except with /home/my_name/catkin_ws/devel/lib/python3/dist-packages/spade/__init__.py
line in the error instead).
I installed my ROS Melodic with this tutorial ...