Problem with Python3 Virtual Environments

Hi,

Whenever I have the virtual environment for Python activate and the script uses modules to interact with the robot, I get this message:

(py3venv) user:~/catkin_ws/src/robot_control$ python test_if.py
Traceback (most recent call last):
  File "test_if.py", line 1, in <module>
    from robot_control_class import RobotControl
  File "/home/simulations/public_sim_ws/src/all/ros_basics_examples/python_course_class/robot_control_class.py", line 7, in <module>
    from tf.transformations import euler_from_quaternion, quaternion_from_euler
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/tf/__init__.py", line 28, in <module>
    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 <module>
    from tf2_py import *
  File "/opt/ros/kinetic/lib/python2.7/dist-packages/tf2_py/__init__.py", line 38, in <module>
    from ._tf2 import *
ImportError: dynamic module does not define module export function (PyInit__tf2)

If I do not source the virtual environment, the code work with the robot, but I always get this message
at the beginning :

the rosdep view is empty: call ‘sudo rosdep init’ and ‘rosdep update’

Is it a known problem and is there a way to fix it?

Thank you
Marc-Antoine

1 Like

To use ROS in python3, you have to custom compile it with python3 and change the source code of some packages like tf2. What exactly are you trying to accomplish?

I was just following the steps in the Python 3 for Robotics course with the Webshell for the exercise 2.1 .

I have the same problem.

I got the same problem.
After using source ~/.py3venv/bin/activate , this occurs.

Do you know anything about this, @albertoezquerro?

I have the same issue. Any solution would be appreciated.

It happens to me as well.
The virtual environment of the course seems to be wrongly configured as trying to run the script invokes python 2.7 (when the course is titled Python 3 for robotics).

Hi @marc-antoine.leclerc, @l.boillod, @78f1d22932fd4f37, @nreyes, @olivier

We just updated the instructions to use the right commands.

Turns out that you also needed to source the file below:

source ~/.catkin_ws_python3/bin/activate

After that, everything should work as expected.

Please let us know in case the problem somehow shows up again.

3 Likes

Thank you! this is what I have been waiting on to continue the course.

1 Like

Hi, i follow your suggestion. but i found there is no /bin folder in catkin_ws_python3 folder.

Oh maybe source the setup.bash file in devel folder is ok.

Hi @984443651,

Welcome to our community.

Yes, the setup.bash is found in the devel folder of the workspace.