ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
2

Using fuerte with python 3

asked 2012-04-24 22:02:22 -0500

languitar gravatar image

updated 2014-01-28 17:12:05 -0500

ngrennan gravatar image

I have seen that several issues regarding python 3 support have been solved recently, e.g. [1]. However, I could not find any information how to actually use the new release with python 3? That means how do I get the python libraries compiled and installed in a python3-compatible pythonpath etc.?

[1] https://code.ros.org/trac/ros/ticket/3166

Ok, trying michikarg's suggestion I end up in this error:

>>> import roslib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/vol/corcse/ros-fuerte/x86_64/src/ros-underlay/ros/core/roslib/src/roslib/__init__.py", line 50, in <module>
    from roslib.launcher import load_manifest
  File "/vol/corcse/ros-fuerte/x86_64/src/ros-underlay/ros/core/roslib/src/roslib/launcher.py", line 42, in <module>
    import rospkg
ImportError: No module named rospkg

jwienke@augit:/vol/corcse/ros-fuerte/x86_64/src/PyYAML-3.10$ echo $PYTHONPATH
/vol/corcse/ros-fuerte/x86_64/lib/python3.1/site-packages:/vol/corcse/ros-fuerte/x86_64/src/ros-underlay/ros/core/roslib/src/

With the patch mentioned below I am now able to use roslib. However rospy and std_msgs do not work:

jwienke@augit:/vol/corcse/ros-fuerte/x86_64/src/ros-underlay/ros/core/roslib/src/roslib$ python3
Python 3.1.2 (r312:79147, Dec  9 2011, 20:47:34) 
[GCC 4.4.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import rospy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/vol/corcse/ros-fuerte/x86_64/lib/python2.6/site-packages/ros_comm-1.8.7-py2.6.egg/rospy/__init__.py", line 47, in <module>
    from std_msgs.msg import Header
  File "/vol/corcse/ros-fuerte/x86_64/lib/python2.6/site-packages/std_msgs/msg/__init__.py", line 1, in <module>
    from _Bool import *
ImportError: No module named _Bool
edit retag flag offensive close merge delete

5 Answers

Sort by » oldest newest most voted
0

answered 2012-05-03 04:36:37 -0500

michikarg gravatar image

updated 2012-05-03 04:36:59 -0500

After playing around a bit with ROS and Python3, i basically got ROS messaging running from python2 and 3! A created a ticket and patches, so feel free to test:

https://code.ros.org/trac/ros/ticket/3949

I also had to fix genpy. You can download the lated trunk (already including my patch the fixes your problem with the _Bool import) from github:

https://github.com/ros/genpy

Cheers

Michi

edit flag offensive delete link more
3

answered 2012-04-25 06:12:29 -0500

joq gravatar image

To limit confusion for those reading this page, @michikarg and @languitar are discussing useful work for future python3 migration, done in branches of various core ROS components.

ROS Fuerte does not officially support python3.

edit flag offensive delete link more

Comments

1

Thanks, i should have pointed that out at the beginning of my answer.

michikarg gravatar image michikarg  ( 2012-04-25 20:06:51 -0500 )edit
1

answered 2012-04-25 03:26:44 -0500

michikarg gravatar image

Here is a patch for /opt/ros/fuerte/lib/python2.7/dist-packages/roslib/stacks.py that allows you to import roslib using Python3. Let me know if this worked for you:

http://ias.cs.tum.edu/~kargm/stacks_py3k.patch

edit flag offensive delete link more
0

answered 2012-04-25 02:56:16 -0500

michikarg gravatar image

I am one step further now! rospkg is now standalone, so you will have to install it with the correct python-version and user:

  1. Git clone it:

    git clone git://github.com/ros/rospkg.git

  2. Install it using Python3:

    python3.2 setup.py install --user

This basically solved the issue of the rospkg-module not beeing found. However it raises another issue for me when iḿ trying to import roslib:

>>> import roslib
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/ros/fuerte/lib/python2.7/dist-packages/roslib/__init__.py", line 54, in <module>
    import roslib.stacks
  File "/opt/ros/fuerte/lib/python2.7/dist-packages/roslib/stacks.py", line 190
    print "ROS_PATHS", ros_paths, env['ROS_PACKAGE_PATH']

This could be related to missing Python3-support in roslib, so i guess we will have to write some more patches....

edit flag offensive delete link more

Comments

I could also fix that very easily... i will write a patch for it...

michikarg gravatar image michikarg  ( 2012-04-25 03:04:31 -0500 )edit
0

answered 2012-04-24 23:51:29 -0500

michikarg gravatar image

updated 2012-04-25 20:08:47 -0500

NOTE: ROS Fuerte DOES NOT officially support Python3! Although the following discussion is about work in progress for partial Python3 compatibility!

Hi,

we patched parts of ros core and ros_comm for python3 so basically messaging should be possible.

You just have to set you Pythonpath to roslib and in set your yaml-folder (in case you need it) to the pyyaml you installed using python3:

export PYTHONPATH=$PYYAML_DIR/pyyaml/lib/python3.2/site-packages:/opt/ros/electric/ros/core/roslib/src

After importing roslib in your python-file, you should be able to normally use roslib.load_manifest and code in Python3.

So far i only used it with ROS Electric, but i will install Fuerte quite soon and check if everything works....

edit flag offensive delete link more

Comments

I just installed Fuerte and ended up with "ImportError: No module named rospkg". Since rospack is now standalone, i installed it for Python2 and 3 but this seems not to work either...

michikarg gravatar image michikarg  ( 2012-04-25 02:41:22 -0500 )edit
1

I'll open a new question for this topic...

michikarg gravatar image michikarg  ( 2012-04-25 02:43:03 -0500 )edit

Question Tools

2 followers

Stats

Asked: 2012-04-24 22:02:22 -0500

Seen: 1,809 times

Last updated: May 03 '12