The Hopper Project -- Import TF error using DeepQ

My hopper project works fine by using Sara learning algorithm, but when I tried to use baseline Deep Q learning, it fails run when import my hopper task file which imports ROS tf package. Below is the code and error message. I try to manually import tf in python2.7, it works fine. BTW, I have source the Python3 virtue environment before that. Anyway to solve that?

Code:
def get_base_rpy(self):
euler_rpy = Vector3()
euler = tf.transformations.euler_from_quaternion(
[self.base_orientation.x, self.base_orientation.y, self.base_orientation.z, self.base_orientation.w])

Error:

Logging to /tmp/openai-2019-10-09-09-54-32-912843
Traceback (most recent call last):
File “/home/user/catkin_ws/src/hopper_new_code/src/start_training_deepq.py”, line 22, in
import hopper_robot_task_env
File “/home/user/catkin_ws/src/hopper_new_code/src/hopper_robot_task_env.py”, line 14, in
import tf
File “/opt/ros/kinetic/lib/python2.7/dist-packages/tf/init.py”, line 28, in
from tf2_ros import TransformException as Exception, ConnectivityException, LookupException, ExtrapolationException
File “/opt/ros/kinetic/lib/python2.7/dist-packages/tf2_ros/init.py”, line 38, in
from tf2_py import *
File “/opt/ros/kinetic/lib/python2.7/dist-packages/tf2_py/init.py”, line 38, in
from ._tf2 import *
ImportError: dynamic module does not define module export function (PyInit__tf2)

Hi @1930748422

Simple mistake, you forgot to source the setup.bash. When activating the Python3 environment you have to do the following:

source ~/.catkin_ws_python3/openai_venv/bin/activate
source ~/.catkin_ws_python3/devel/setup.bash

Hi Simon,
Thanks for your help. I tried but got same error message. Have you successfully import tf under Python3 enviroment?

It did work for me. The way I tested it was like this:

source ~/.catkin_ws_python3/openai_venv/bin/activate
python
>>>import tf

ERROR

source ~/.catkin_ws_python3/openai_venv/bin/activate
source ~/.catkin_ws_python3/devel/setup.bash
python
>>>import tf

No ERROR

Did you copy/paste my commands exactly? Perhaps you sourced the python2 setup.bash, this is wrong. You have to source the hidden python3 setup.bash

Thanks for your help. I skipped some unit, going directly to hopper training and didn’t note the request to source python3 setup file. Now the problem becomes roslaunch cannot find the hopper package after source python3 setup file. I found this topic “Chapter 8 - Problem with launch file” has same issue, so I replied there and hope to get answer.

After delete build/devel file and re-compile at virtue environment with below command, I was able to launch successfully.

source ~/.catkin_ws_python3/openai_venv/bin/activate
source ~/.catkin_ws_python3/devel/setup.bash
cd /home/user/catkin_ws
rm -rf build devel
catkin_make
source devel/setup.bash

1 Like

this solution is not working in robotigniteacademy… can someone test and see maybe something is changed in openai_venv. I am unable to solve cubli with deepq

Thanks
Navid

Hi @Navid.Mellatshahi, did you actually activate the python3 environment and source that exact setup.bash?