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

Revision history [back]

click to hide/show revision 1
initial version
>>> print('\n'.join(sys.path))

/usr/local/lib/jython2.7.0/Lib
__classpath__
__pyclasspath__/
/usr/local/lib/jython2.7.0/Lib/site-packages
/usr/lib/python2.7/dist-packages
/usr/local/lib/python2.7/dist-packages
>>> import rospy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named rospy

Seeing as ROS is installed in /opt/ros/$ROSDISTRO, with the Python packages all in /opt/ros/$ROSDISTRO/lib/python2.7/dist-packages, it seems without that path on the sys.path it would be expected Jython can't import rospy.

>>> print('\n'.join(sys.path))

/usr/local/lib/jython2.7.0/Lib
__classpath__
__pyclasspath__/
/usr/local/lib/jython2.7.0/Lib/site-packages
/usr/lib/python2.7/dist-packages
/usr/local/lib/python2.7/dist-packages
>>> import rospy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named rospy

Seeing as ROS is installed in /opt/ros/$ROSDISTRO, with the Python packages all in /opt/ros/$ROSDISTRO/lib/python2.7/dist-packages, (at least for ROS versions which use Python 2), it seems without that path on the sys.path it would be expected Jython can't import rospy.

>>> print('\n'.join(sys.path))

/usr/local/lib/jython2.7.0/Lib
__classpath__
__pyclasspath__/
/usr/local/lib/jython2.7.0/Lib/site-packages
/usr/lib/python2.7/dist-packages
/usr/local/lib/python2.7/dist-packages
>>> import rospy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named rospy

Seeing as ROS is installed in /opt/ros/$ROSDISTRO, with the Python packages all in /opt/ros/$ROSDISTRO/lib/python2.7/dist-packages (at least for ROS versions which use Python 2), it seems without that path on the sys.path it would be expected Jython can't import rospy.


Edit:

I'm not sure what you're getting at. Should I add to Jython /opt/ros/$ROSDISTRO?

No. If you had not built ROS from source, you would have had to add /opt/ros/$ROSDISTRO/lib/python2.7/dist-packages, as that's where all the Python packages live.

By the way I build it from source because Ubuntu 18.04 does not support ROS Kinetic so isntead of /opt/ros/$ROSDISTRO I should have to use ~/ros_catkin_ws.

This would be the right solution. But which is the correct one I have to use?

>>> sys.path.append('/home/openhabvm/ros_catkin_ws/build_isolated')
>>> sys.path.append('/home/openhabvm/ros_catkin_ws/devel_isolated')
>>> sys.path.append('/home/openhabvm/ros_catkin_ws/install_isolated')
>>> import rospy
>>>

Build, Devel or Install?

If you have an install space, you must use it. If you don't have an install space (so only a devel), then use the devel space.

In your case that's install_isolated, as you probably used catkin_make_isolated to build your workspace.

I am amazed. It didn't work if I left out individual things, and somehow I also have to consider an appropriate order. One also needs:

>>> sys.path.append('/home/openhabvm/ros_catkin_ws')
>>> sys.path.append('/home/openhabvm/ros_catkin_ws/src')

I would not expect this to be needed, as it isn't when using a regular Python interpreter. But perhaps Jython is different.

and:

>>> sys.path.append('/usr/local/lib/python2.7/dist-packages')

It could be this is needed if Jython is not using the default dist-packages (ie: the one managed by apt) and you've installed certain ROS Python dependencies manually in /usr/local.

The build-ROS-from-sources instructions do not do that though, so that would have been something you've done yourself.

Well it is not the whole ROS integration. I can not import std_msgs as example. I got this error:

>>> from std_msgs.msg import String
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name String

Of course, I also have a suspicion where this comes from. But I won't be the only one who first comes up with one solution and then looks for the next. It may be possible to link it later, should my project succeed.

As I don't know exactly what you've done, I can't comment on this. std_msgs is a pretty low-level dependency though, so if you can import rospy, I would expect std_msgs to also be present.

>>> print('\n'.join(sys.path))

/usr/local/lib/jython2.7.0/Lib
__classpath__
__pyclasspath__/
/usr/local/lib/jython2.7.0/Lib/site-packages
/usr/lib/python2.7/dist-packages
/usr/local/lib/python2.7/dist-packages
>>> import rospy
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named rospy

Seeing as ROS is installed in /opt/ros/$ROSDISTRO, with the Python packages all in /opt/ros/$ROSDISTRO/lib/python2.7/dist-packages (at least for ROS versions which use Python 2), it seems without that path on the sys.path it would be expected Jython can't import rospy.


Edit:

I'm not sure what you're getting at. Should I add to Jython /opt/ros/$ROSDISTRO?

No. If you had not built ROS from source, you would have had to add /opt/ros/$ROSDISTRO/lib/python2.7/dist-packages, as that's where all the Python packages live.

By the way I build it from source because Ubuntu 18.04 does not support ROS Kinetic so isntead of /opt/ros/$ROSDISTRO I should have to use ~/ros_catkin_ws.

This would be the right solution. But which is the correct one I have to use?

>>> sys.path.append('/home/openhabvm/ros_catkin_ws/build_isolated')
>>> sys.path.append('/home/openhabvm/ros_catkin_ws/devel_isolated')
>>> sys.path.append('/home/openhabvm/ros_catkin_ws/install_isolated')
>>> import rospy
>>>

Build, Devel or Install?

If you have an install space, you must use it. If you don't have an install space (so only a devel), then use the devel space.

In your case that's install_isolated, as you probably used catkin_make_isolated to build your workspace.

I am amazed. It didn't work if I left out individual things, and somehow I also have to consider an appropriate order. One also needs:

>>> sys.path.append('/home/openhabvm/ros_catkin_ws')
>>> sys.path.append('/home/openhabvm/ros_catkin_ws/src')

I would not expect this to be needed, as it isn't when using a regular Python interpreter. But perhaps Jython is different.

and:

>>> sys.path.append('/usr/local/lib/python2.7/dist-packages')

It could be this is needed if Jython is not using the default dist-packages (ie: the one managed by apt) and you've installed certain ROS Python dependencies manually in /usr/local.

The build-ROS-from-sources instructions do not do that though, so that would have been something you've done yourself.

Well it is not the whole ROS integration. I can not import std_msgs as example. I got this error:

>>> from std_msgs.msg import String
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name String

Of course, I also have a suspicion where this comes from. But I won't be the only one who first comes up with one solution and then looks for the next. It may be possible to link it later, should my project succeed.

As I don't know exactly what you've done, I can't comment on this. std_msgs is a pretty low-level dependency though, so if you can import rospy, I would expect std_msgs to also be present.


Edit 2: I'm wondering whether it wouldn't have been simpler to use rospypi/simple to setup a self-contained, minimal virtualenv with just rospy and some extra packages, instead of building ROS Kinetic from source on Ubuntu Bionic.