You can install GCC from the OpenCSW repository: https://www.opencsw.org/packages/CSWgcc5core/. Everything from the repository is installed to /opt/csw/bin in order not to interfere with the system files and can be uninstalled simply by removing all packages with names beginning with CSW and deleting the /opt/csw directory - you can also install Python into a custom directory using the option --prefix to configure.
Alternatively you can install the Solaris Studio from the Oracle website, but I'm not sure whether it can build Python 3.
UPDATE: There is a solution that does not require installing third party repositories. (Apparently GCC 3 from Sun/Oracle can build Python 3.7.)
Make sure you have the package SUNWgcc installed. (You can find it on the Solaris 10 ISO.)
Then you can install Python 3.7 with the use of some hacks (assuming you are in the directory with its source):
# ln -s /usr/sfw/bin/gar /usr/sfw/bin/ar
# ./configure --prefix=/opt/python3
# gmake install
# unlink /usr/sfw/bin/ar
good tip, thank you. Worked for our build nodes