Ask Your Question

Python 3 in ROS indigo

asked 2015-05-18 07:21:57 -0500

gagarin gravatar image

I have a script in python 3, it reads data from a serial port, do some processing and return some integer and float values. This script manipulates bytes in a way that it will be time consuming for me to adapt it to python2. Is there a way to run python3 script in ROS Indigo? I dont use any ros package in python, only external libraries like pyserial.

I try to install python3-pkg, but the package remove many(if not all) of my ros packages and do not install any substitutes.


Iuro Nascimento

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2016-04-19 09:42:57 -0500

gavran gravatar image

updated 2016-04-19 09:43:38 -0500

I don't know why the apt installation of rospkg removes existing packages, but the same happened to me. What works, actually, is to create a virtual machine with python3 interpreter (virtualenv -p /usr/bin/python3, for example) and under it run pip install rospkg).

(additionally, you'd have to run pip install catkin_pkg, in order to run python3 scripts. I can confirm this approach works for basic ROS functionality - establishing nodes, publishing and subscribing to topics etc.However, there are packages that don't work with python3. In order to combine both - scripts that have to use python3 and those that have to use python2, I define in the shebang the interpreter to use, e.g. #!/home/bot/virtualEnvs/v3/bin)

edit flag offensive delete link more



The problem is that many ROS Python packages install different versions under the same file name, so the python3-foo-bar package has to "Conflict" with the corresponding python-foo-bar.

joq gravatar image joq  ( 2016-04-20 12:03:31 -0500 )edit

I followed these steps but couldn't make it work. I posted my question here. Could you please write down these steps from the beginning? Do I just need to run these two commands virtualenv -p /usr/bin/python3 myenv and under myenv run pip install rospkg?

Ravi Joshi gravatar image Ravi Joshi  ( 2020-01-12 05:11:43 -0500 )edit

answered 2016-04-22 05:02:36 -0500

Pincello gravatar image

I had the same Problem with Python 3 . The easiest way is to use Python 2.7. instead, or if your really need 3 use virtualenv as mentioned above. I migrated my .py files to pyhon2 and there were nearly no changes necessary. Additionaly i was able to use other packages, wich are still only aviable for Python 2.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2015-05-18 07:21:57 -0500

Seen: 3,970 times

Last updated: Apr 22 '16