I have chronically had the issue where I had to run python2 if I ever wanted to use the tf2 libraries. I use primarily kinetic+16.04 and melodic+18.04. I typically get the issue:
>>> import tf2_ros
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/opt/ros/melodic/lib/python2.7/dist-packages/tf2_ros/__init__.py", line 38, in <module>
from tf2_py import *
File "/opt/ros/melodic/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)
I've seen it documented that this issue is caused by mixing python2 and python3, which I understand. However, I haven't found a good posting, documentation, or guide on how to override the tendency for python2 to cause issues by default, as melodic uses 2.7 from the start. With the shift to python3 officially in full force, I wanted to finally figure out how to do this, as I will likely still have to use kinetic and melodic for the foreseeable future and won't be able to immediately adopt noetic and ROS2 due to lab congruity, but I don't want the current packages I'm writing to be python2 dependent. I've had numerous students I advise run into the same problem and I haven't been able to help them. Assuming a clean install of Ubuntu 18.04+Melodic, how would I go about running tf2 on python3? I'd like to document this and circulate it around my university, as it is a common issue that many people simply avoid rather than try to fix, and is preventing some people from doing away with python2, as I have done up until this point. I'd appreciate if anyone on the geometry2 team could assist, and I'd be glad to return a write up guide to help people that are in a similar position.
Thanks in advance
Originally posted by gmetts on ROS Answers with karma: 3 on 2020-01-28
Post score: 0