Ran into the same issue, you’re probably missing headers for libpython on your system, you can install them with something like sudo yum install python3-devel.x86_64.
Our CMake needs to be tweaked a bit, it seems that here the version string is empty despite PYTHONLIBS_FOUND being true: https://github.com/pytorch/pytorch/blob/db5e5b439c454d657cfa8f08a096cf68e203f2a8/cmake/Dependencies.cmake#L959 36
cc @malfet FYI