On Melodic the binary installation of ROS is built against the python2 (REP 3) version on the system.
If you want to use tf2_ros or any other python elements of ROS Melodic in python3 you need to build it from source in an environment where python3 is the default. We made the effort to test all packages up to desktop and they are generally expected to work with python3 in Melodic. Beyond that you may find packages that are not dual compatible.
You will have to modify the source installation instructions to setup python3 in your environment. Make sure to always be in the python3 environment when interacting with that installation. You will also have to install all the python depeendencies into your python3 environment manually, and the rosdeps on melodic will install the python2 dependencies as that's what the default is for melodic.
If you move forward to noetic the default is python3 and you can use it there.