U5 Part 2 Sample Code Broken

The “move_fetch_robot_client.py” code doesn’t work. I’ve tried running it both in python2 as the instructions say to, and in python3 because I thought that might be the issue. Neither work. It might have to do with the placement in the “my_catkin_ws_python3/src” folder, but I found that ROS doesn’t recognize the package unless it is placed there due to the formatting from previous steps (even with the use of deactivate).

Below are the errors I got when trying to run the code using python2.

user:~/catkin_ws/src$ rosrun my_face_recogniser move_fetch_robot_client.py
Traceback (most recent call last):
File “/home/user/catkin_ws/src/my_catkin_ws_python3/src/face_recogniser/src/move_fetch_client.py”, line 36, in
from moveit_python import MoveGroupInterface,PlanningSceneInterface,PickPlaceInterface
File “/opt/ros/kinetic/lib/python2.7/dist-packages/moveit_python/init.py”, line 6, in
from .move_group_interface import MoveGroupInterface
File “/opt/ros/kinetic/lib/python2.7/dist-packages/moveit_python/move_group_interface.py”, line 30, in
from tf.listener import TransformListener
File “/home/user/.catkin_ws_python3/devel/lib/python3/dist-packages/tf/init.py”, line 35, in
File “”, line 30, in
File “/home/user/.catkin_ws_python3/devel/lib/python3/dist-packages/tf2_ros/init.py”, line 35, in
File “”, line 38, in
File “/home/user/.catkin_ws_python3/devel/lib/python3/dist-packages/tf2_py/init.py”, line 35, in
File “”, line 38, in
ImportError: dynamic module does not define init function (init_tf2)

Hi ,

Just tried to just create the move_fetch_robot_client.py from scratch, copied and pasted the code that is in the notebook and executed a simple

python move_fetch_robot_client.py

And it worked perfectly. So please try that just in case there is something you missed.

My issues were caused by the splitting of packets for python2 and python3. The first problem is that the “deactivate” command does not entirely work for switching between the two. After running:

source ~/.py3venv/bin/activate
source ~/catkin_ws/src/my_catkin_ws_python3/devel/setup.bash
rospack profile

in a terminal, that terminal treats ~/catkin_ws/src/my_catkin_ws_python3 as the ROS source directory, and will not be able to recognize a packet in ~/catkin_ws/src, even after “deactivate” is used. I needed to run deactivate then “source ~/catkin_ws/devel/setup.bash” in order to access packets within catkin_ws/src.

In addition to this, if python2 code is placed within ~/catkin_ws/src/my_catkin_ws_python3/src, it will not be able to run, even if the python3 environment has been deactivated (this, in combination with the source directory issue, was the cause of my problem).