System information
- OS: Ubuntu 18.04
- ROS version: Melodic
- Conda environment: python=3.7 (Needed for a python3 processing module)
Problem explanation
I try to create a message filter that subscribes to two sensor_msg
topics after which a python3 module processes the Color and depth data in a callback function. To do this, I created the following script to achieve this:
#!/usr/bin/env python3
## Import standard library packages ##
import sys
## Import ROS python packages ##
import rospy
import sensor_msgs
from message_filters import ApproximateTimeSynchronizer, Subscriber
def gotimage(image, camerainfo):
assert image.header.stamp == camerainfo.header.stamp
print("got an Image and CameraInfo")
## Main script ##
# Only runs when this script is executed directly
if __name__ == "__main__":
## Initialize ros node ##
rospy.init_node('grasp_planner', anonymous=True)
image_sub = Subscriber("/kinect2/hd/image_color", sensor_msgs.msg.Image)
camera_sub = Subscriber("/kinect2/hd/camera_info", sensor_msgs.msg.CameraInfo)
## Create message_filter ##
ats = ApproximateTimeSynchronizer([image_sub, camera_sub], queue_size=5, slop=0.1)
ats.registerCallback(gotimage)
rospy.spin()
Unfortunately, after trying to run this script, I get the following error message:
/home/ricks/miniconda3/envs/panda_autograsp/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:526: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint8 = np.dtype([("qint8", np.int8, 1)])
/home/ricks/miniconda3/envs/panda_autograsp/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:527: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint8 = np.dtype([("quint8", np.uint8, 1)])
/home/ricks/miniconda3/envs/panda_autograsp/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:528: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint16 = np.dtype([("qint16", np.int16, 1)])
/home/ricks/miniconda3/envs/panda_autograsp/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:529: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_quint16 = np.dtype([("quint16", np.uint16, 1)])
/home/ricks/miniconda3/envs/panda_autograsp/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:530: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
_np_qint32 = np.dtype([("qint32", np.int32, 1)])
/home/ricks/miniconda3/envs/panda_autograsp/lib/python3.7/site-packages/tensorflow/python/framework/dtypes.py:535: FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecated; in a future version of numpy, it will be understood as (type, (1,)) / '(1,)type'.
np_resource = np.dtype([("resource", np.ubyte, 1)])
[ERROR] [1566834367.342856]: bad callback: <bound method Subscriber.callback of <message_filters.Subscriber object at 0x7fb849e44f50>>
Traceback (most recent call last):
File "/opt/ros/melodic/lib/python2.7/dist-packages/rospy/topics.py", line 750, in _invoke_callback
cb(msg)
File "/opt/ros/melodic/lib/python2.7/dist-packages/message_filters/__init__.py", line 75, in callback
self.signalMessage(msg)
File "/opt/ros/melodic/lib/python2.7/dist-packages/message_filters/__init__.py", line 57, in signalMessage
cb(*(msg + args))
File "/opt/ros/melodic/lib/python2.7/dist-packages/message_filters/__init__.py", line 282, in add
for vv in itertools.product(*[zip(*s)[0] for s in stamps]):
File "/opt/ros/melodic/lib/python2.7/dist-packages/message_filters/__init__.py", line 282, in <listcomp>
for vv in itertools.product(*[zip(*s)[0] for s in stamps]):
TypeError: 'zip' object is not subscriptable
Looks like the package released a pull request but it is not yet merged. In this, cause I'm unfortunately in a deadlock since my robot supports ROS up to version melodic and the image processing package is written in python3. Does anybody know what is the best way to solve my problem?
What I already tried
- I tried setting the
export ROS_PYTHON_VERSION=3
environmental variable. - Building the rospy from source.
Building rospy from source
- Clone the rospy package into your
catkin_ws
. - Setting the
export ROS_PYTHON_VERSION=3
environmental variable. - Building the rospy package using the
catkin_make -j4 -DCMAKE_BUILD_TYPE=Release -DFranka_DIR:PATH="$HOME/libfranka/build" -Dfreenect2_DIR="$HOME/freenect2/lib/cmake/freenect2"
command. - Source the
devel/setup.bash
file.
After these steps my python path becomes PYTHONPATH=/home/ricks/panda_autograsp_ws/devel/lib/python2.7/dist-packages:/opt/ros/melodic/lib/python2.7/dist-packages
.
When I try to run the python3 node I now get the following error:
Traceback (most recent call last):
File "/home/ricks/panda_autograsp_ws/src/rospy/src/rospy/client.py", line 100, in load_command_line_node_params
if rosgraph.names.is_legal_remap(arg):
AttributeError: module 'rosgraph.names' has no attribute 'is_legal_remap'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/ricks/panda_autograsp_ws/src/panda_autograsp/nodes/grasp_planner_node.py", line 39, in <module>
rospy.init_node('grasp_planner', anonymous=True)
File "/home/ricks/panda_autograsp_ws/src/rospy/src/rospy/client.py", line 326, in init_node
_init_node_params(argv, name)
File "/home/ricks/panda_autograsp_ws/src/rospy/src/rospy/client.py", line 183, in _init_node_params
params = load_command_line_node_params(argv)
File "/home/ricks/panda_autograsp_ws/src/rospy/src/rospy/client.py", line 107, in load_command_line_node_params
raise rospy.exceptions.ROSInitException("invalid command-line parameters: %s"%(str(e)))
rospy.exceptions.ROSInitException: invalid command-line parameters: module 'rosgraph.names' has no attribute 'is_legal_remap'
Originally posted by rickstaa on ROS Answers with karma: 111 on 2019-08-26
Post score: 0
Original comments
Comment by gvdhoorn on 2019-08-26:\
Does anybody know what is the best way to solve my problem?
build rospy
with the patch in your Catkin workspace (it wouldn't really be building, as rospy
is all Python, but you'll need to do it anyway for Catkin to properly overlay the apt
version with the version in your workspace)?
Btw: you appear to be mixing Python 2.x and Python 3 PYTHONPATH
s. That is probably not a good idea.
Comment by rickstaa on 2019-08-26:
@gvdhoorn Thanks a lot for your answer. You mean that I have to build the ros_comm
package (which includes the rospy
module) from the source from within my catkin workspace as you explained in #252478 and #295012?
Btw: you appear to be mixing Python 2.x and Python 3 PYTHONPATHs. That is probably not a good idea.
My PYTHONPATH currently is /opt/ros/melodic/lib/python2.7/dist-packages
since I sourced the devel/setup.bash
of my workspace before running the python node. Do I need to remove this line when using a python3 ROS package?
Comment by rickstaa on 2019-08-26:\
Btw: you appear to be mixing Python 2.x and Python 3 PYTHONPATHs. That is probably not a good idea.
Ah, I now see what goes wrong. When I try to run the node in the python 3 virtual environment it gives me the No module named 'rospy' not found
error.
Comment by gvdhoorn on 2019-08-26:
You don't need to build all of ros_comm
most likely. Copying out just the rospy
client library package should be sufficient (not very maintainable, but it should work).
Comment by rickstaa on 2019-08-26:
@gvdhoorn Thanks for your explanation. I tried building the rospy
module from source but I now get a new attribute error
. The steps I performed while doing this can be found appended to the question above.
The other strange thing is that the python3 package still ends up in the /home/ricks/panda_autograsp_ws/devel/lib/python2.7/dist-packages
folder instead of the /home/ricks/panda_autograsp_ws/devel/lib/python3.7/dist-packages
.
Comment by gvdhoorn on 2019-08-27:
I don't believe that is strange: from what you show here it would appear you're still mixing Python 2 and Python 3 (your Conda environment). Without special care, Catkin will use Python 2. source
ing a workspace from inside your Conda environment will not change that.
Note that the patch only makes that particular part of rospy
language-compatible with Python 3, if you're still using Python 2, Python 2 will still be used.
You may try the procedure outlined here, but from within your Conda environment instead of a plain venv.
No guarantees, but it could work.
Comment by rickstaa on 2019-08-29:
@gvdhoorn thanks a lot for the explanation. I will do some testing and report my solution back as an answer.
Comment by rickstaa on 2019-08-31:
@gvdhoorn As I managed to use the package with python 2.7, after all, I didn't test the procedure you outlined in this topic. I, however, added an answer based on my current findings below so I can close this question. Although I know I saw a python 3 transitioning status REP for the ROS main packages (see the tag) somewhere I was unable to find it again. Do you maybe know where I can find such an overview? Feel free to correct me if I misunderstood something in my answer below.