Trouble building pywin32 with Visual Studio 2005

"Martin v. Löwis" martin at v.loewis.de
Wed Nov 14 14:26:06 EST 2007


> Now, my theory on this issue is that DLLs like win32api.pyd, which I
> acquired pre-built, were built with Visual Studio 2003, and they
> depend on msvcr71.dll. My Python/MFC application, on the other hand,
> was built with Visual Studio 2005, and is linking with msvcr80.dll. If
> memory gets allocated through one DLL, and an attempt is made at
> freeing it in the other DLL, bad things can happen, since the freeing
> DLL doesn't have any header information on the allocated memory.

That is the likely cause, yes.

> In order to test this theory (and potentially fix it), I want to re-
> build the pywin32 stuff using Visual Studio 2005.

That might not be sufficient. You have to rebuild Python itself as well.


> The logical conclusion to jump to from this error message is that
> pywin32 is trying to build with VS2005, but it thinks that Python was
> built with VS2003. Well, in a manner of speaking, that is true. I did
> have a regular Python installation in C:\Python25, straight from one
> of the MSI installers. That regular Python installation was
> undoubtedly compiled with VS2003. I guess what I need to do is find a
> way to replace the default installation, or certain files within it,
> with stuff I compiled myself using VS2005. I tried replacing all of
> the python25[_d].dll and python[w][_d].exe files with those that I
> built, and that isn't helping.

That is likely to happen. distutils doesn't actually *check* what CRT
or VC version Python was built with, instead, it *knows*, hardcoded.

> I tried going through the setup.py code to find out where it is
> acquiring this "Python was built with Visual Studio 2003" information,
> but I keep getting lost in the code, so I can't figure out which, if
> any, file(s) to change/replace.

If you know what you are doing, you can override the logic of distutils.
Set up an SDK environment (with LIBRARY, INCLUDE and everything), then
also set the MSSdk environment variable (which should get set if you
use the standard environment batch file from the SDK), and then also
set DISTUTILS_USE_SDK. Then distutils will trust that the environment
you set up works correctly, and will use it without further questioning.

HTH,
Martin



More information about the Python-list mailing list