The current implementation nicely takes into account when the python interpreter is symlinked (or transitively within a symlinked directory). Sadly, os.path.islink returns false on Windows if instead of Windows symlinks, junctions are used. This has caused me issues after I started using scoop as my package manager on Windows, which creates junctions instead of symlinks.
The fix proposed in this patch is to check whether realpath returns a different path to exe, and if it does, to simply try again with that path.
The code could also be simplified since sys.executable is guaranteed to be absolute, and os.readlink, which can return a relative path, is no longer used.
Tested on Windows 11 with Python 3.11 as interpereter and Ubuntu 18.04 with Python 3.6