<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7654.12">
<TITLE>PIL 1.1.6, python 64bit on Windows XP x64</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/rtf format -->
<BR>

<P><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">Hi,</FONT></SPAN>
</P>

<P><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">I've been trying to get PIL 1.1.6 working on python 64bit:</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">Python version : 2.5.2 (r252:60911, Feb 21 2008, 13:17:27) [MSC v.1400 64 bit (AMD64)]</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">OS : Windows XP Professional x64 SP2.</FONT></SPAN>
</P>

<P><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">The installer on the main download page appears to only be valid for 32bit python, causing a variety of import errors when used with 64bit python.</FONT></SPAN></P>

<P><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">Is there any plan to provide an installer for 64bit versions of python on 64 bit Windows in the future?</FONT></SPAN>
</P>

<P><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">I've sucessfully built a version locally with DevStudio 2005, including zlib and jpeg-6b support. I'll detail the steps required later for posterity, it may be useful for someone browsing this forum at a later time - I have no plans to provide an installer myself!</FONT></SPAN></P>

<P><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">&nbsp;I did have to work around an issue, which I thought was worth raising to you folks, in case there was a better way to fix this.</FONT></SPAN></P>

<P><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">After building locally (setup.py build, setup.py install) and importing PIL.Image, the quick test detailed below caused my python process to crash.</FONT></SPAN></P>

<P><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">Import PIL.Image</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">Im = PIL.Image.open('my_image.gif')</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">Im2 = im.rotate(45)</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">Im2.save()</FONT></SPAN>
</P>

<P><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">At the point of saving, the process crashes with a windows IO exception. Digging into the python, and then into the C extension code, I found the problem appears to be due to some conflict with using the file descriptor that's being passed into _encode_to_file (encode.c) from _save in ImageFile.py (line 492 in ImageFile.py in the source I'm looking at). After trying various different things, I found that I could not use the file descriptor int (acquired via fp.fileno(), line 469 in ImageFile.py) passed into encode_to_file - trying to write to a file using that file descriptor was causing the crash (for example, line 164 in encode.c). I tried using _rdinfo to convert the file descriptor to a FILE pointer, and work with that, but that crashed in _rdinfo, and I tried a couple of different conversions using calls like</FONT> <FONT SIZE=2 FACE="Courier New">_get_osfhandle</FONT></SPAN></P>

<P><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">, but pretty much everything I tried continued to cause crashes. My knowledge of Windows is pretty minimal, so I've no idea why using that file descriptor should be problematic (and, presumably, works just fine with the 32bit python version).</FONT></SPAN></P>

<P><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">After taking a step back, I realised that the code in ImageFile has two paths, and by putting a forced call to raise an AttributeError around line 469 caused the _save function to take the top code path, and this works just fine for me. I ended up modifying the code to look like this:</FONT></SPAN></P>

<P><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">Line 467, ImageFile.py</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; try:</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; # FIXME: force an AttributeError exception to use the python file-compatible object path</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; raise AttributeError</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fh = fp.fileno()</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fp.flush()</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">&nbsp;&nbsp;&nbsp; except AttributeError:</FONT></SPAN>

<BR><SPAN LANG="en-gb">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <FONT COLOR="#800080" SIZE=2 FACE="Arial">...</FONT></SPAN>
</P>

<P><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">It's not clean, but it appears to work. Anyone got any ideas why? Can someone suggest a cleaner way of doing this?</FONT></SPAN>
</P>
<BR>
<BR>
<BR>

<P><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">If anyone is interested, here's the steps I followed to get PIL 1.1.6 working locally for me - DevStudio 2005 required.</FONT></SPAN>
</P>

<P><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">Step 1: unarchive the source to a location locally, I'll refer to this as the build root directory (in my case, c:\temp\Imaging-1.1.6)</FONT></SPAN></P>

<P><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">Step 2: run the visual studio 2005 command prompt for the relevant bits of the OS</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">(in my case from Windows start menu: Programs -&gt; (somewhere) -&gt; Microsoft Visual Studio 2005 -&gt; Visual Studio Tools -&gt; Visual Studio 2005 x64 Win64 Command Prompt</FONT></SPAN></P>

<P><SPAN LANG="en-gb"></SPAN><A HREF="http://docs.python.org/dist/module-distutils.msvccompiler.html"><SPAN LANG="en-gb"><U></U><U><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">http://docs.python.org/dist/module-distutils.msvccompiler.html</FONT></U></SPAN></A><SPAN LANG="en-gb"></SPAN>
</P>

<P><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">Step 3: set up the following environment variables at the command prompt</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">set DISTUTILS_USE_SDK=1</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">set MSSdk=1</FONT></SPAN>
</P>

<P><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">Step 4: edit ImageFile.py as described above</FONT></SPAN>
</P>

<P><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">Step 5: (optional) edit setup.py to point to the correct locations for zlib, jpeg-6b, etc. source and built libs</FONT></SPAN>
</P>

<P><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">Step 6 : build PIL using &quot;setup.py build&quot; in the build root directory.</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">(it's worth at this point confirming that you're running setup.py with the correct (64bit) version of python - slap a pdb break in there and check sys.version if needed)</FONT></SPAN></P>

<P><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">Step 7 : embed the manifests for the two DLLS by running mt.exe in the build root directory:</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">Mt.exe -manifest build\lib.win32-2.5_imaging.pyd.manifest -outputresource:build\lib.win32-2.5_imaging.pyd;2</FONT></SPAN>

<BR><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">Mt.exe -manifest build\lib.win32-2.5_imagingmath.pyd.manifest -outputresource:build\lib.win32-2.5_imagingmath.pyd;2</FONT></SPAN>

<BR><SPAN LANG="en-gb"></SPAN><A HREF="http://msdn.microsoft.com/en-us/library/ms235591(VS.80).aspx"><SPAN LANG="en-gb"><U></U><U><FONT COLOR="#0000FF" SIZE=2 FACE="Arial">http://msdn.microsoft.com/en-us/library/ms235591(VS.80).aspx</FONT></U></SPAN></A><SPAN LANG="en-gb"></SPAN>
</P>

<P><SPAN LANG="en-gb"><FONT COLOR="#800080" SIZE=2 FACE="Arial">Step 8: install PIL (setup.py install)</FONT></SPAN>
</P>
<BR>

</BODY>
</HTML>