Index: Lib/ctypes/util.py =================================================================== --- Lib/ctypes/util.py (revision 59887) +++ Lib/ctypes/util.py (working copy) @@ -5,7 +5,20 @@ # find_library(name) returns the pathname of a library, or None. if os.name == "nt": + import re + def find_msvcrt(): + # To access functions of the C runtime library the same dll + # that Python itself is linked to must be used. A not very + # robust but working hack is to scan the executable for the + # string (better would be to locate the real import table and + # parse that, but I'm too lazy for this now). + bytes = open(sys.executable, "rb").read() + match = re.search("msvcr([0-9]+|t)d?.dll", bytes, re.IGNORECASE) + return match.group(0) + def find_library(name): + if name in ("c", "m"): + return find_msvcrt() # See MSDN for the REAL search order. for directory in os.environ['PATH'].split(os.pathsep): fname = os.path.join(directory, name)