0
$\begingroup$

Rosanswers logo

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.

Thanks,

Iuro Nascimento


Originally posted by gagarin on ROS Answers with karma: 41 on 2015-05-18

Post score: 4

$\endgroup$

1 Answer 1

0
$\begingroup$

Rosanswers logo

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)


Originally posted by gavran with karma: 526 on 2016-04-19

This answer was ACCEPTED on the original site

Post score: 2


Original comments

Comment by joq on 2016-04-20:
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.

Comment by ravijoshi on 2020-01-12:
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?

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.