Getting PIL to work on Windows 7, 64 bit

This is the place for queries that don't fit in any of the other categories.

Getting PIL to work on Windows 7, 64 bit

Postby SifJar » Tue Feb 12, 2013 11:20 pm

I have been playing about with Python a little lately and have been trying to get PIL (Python Imaging Library) to work. I downloaded the prebuilt version from here: http://www.pythonware.com/products/pil/ (the python 2.7 version, as that is what I have installed)

First off, the installer couldn't find my Python installation. I realised from some googling that this was due to the 64 bit OS on my computer, and the relevant registry entries therefore being in the wrong place. Following instructions online, I was able to copy the registry entries to the correct place and the installer could then complete successfully...or so I thought.

I then tried to create a simple little script to crop an image, to test out PIL. However, on running it, I got an error: "_imaging c module not installed"

I looked in the python DLL folder, and sure enough _imaging.pyd (which googling has led me to believe should be present there) was absent. I then uninstalled PIL and reinstalled it from an alternative location: http://www.lfd.uci.edu/~gohlke/pythonlibs/

This made no difference. So I then decided to try using PIP to install PIL (having now removed the second PIL installation as well). This seemed to download the source and try to build it, but then I came up against another problem: gcc from MinGW gave an error when trying to compile the _imaging module. The error was this:

gcc: error: unrecognized command line option '-mno-cygwin'

I did some more googling, and came across this: http://bugs.python.org/issue12641

Apparently, it's a known issue with recent builds of GCC. The suggestion there was to remove all mentions of "-mno-cygwin" from the file "cygwinccompiler.py" in the python Lib\distutils directory. I did that and no longer got the above error, but now I got this one instead:

Code: Select all
c:\mingw\bin\../lib/gcc/mingw32/4.7.2/../../../../include/basetsd.h:50:21: error
: duplicate 'signed'

c:\mingw\bin\../lib/gcc/mingw32/4.7.2/../../../../include/basetsd.h:50:21: error
: two or more data types in declaration specifiers

c:\mingw\bin\../lib/gcc/mingw32/4.7.2/../../../../include/basetsd.h:51:22: error
: duplicate 'short'

c:\mingw\bin\../lib/gcc/mingw32/4.7.2/../../../../include/basetsd.h:56:23: error
: duplicate 'unsigned'

c:\mingw\bin\../lib/gcc/mingw32/4.7.2/../../../../include/basetsd.h:56:23: error
: two or more data types in declaration specifiers

c:\mingw\bin\../lib/gcc/mingw32/4.7.2/../../../../include/basetsd.h:57:24: error
: duplicate 'unsigned'

c:\mingw\bin\../lib/gcc/mingw32/4.7.2/../../../../include/basetsd.h:57:24: error
: duplicate 'short'

error: command 'gcc' failed with exit status 1


So in short, I am still no closer to having PIL working.

Basically my question is: is there some distribution of PIL which includes _imaging.pyd (assuming that is the file I need), or some other simpler way to get PIL working? (Ideally I would like to get gcc working properly as well, but if I can just get PIL for now, that'll be fine for me)

EDIT: Just to be absolutely clear:

OS: Windows 7 64 bit
Python version: 2.7.3
SifJar
 
Posts: 3
Joined: Tue Feb 12, 2013 11:04 pm

Re: Getting PIL to work on Windows 7, 64 bit

Postby metulburr » Tue Feb 12, 2013 11:54 pm

In a fresh install of windows 7 in a virtual box after installing python2.7, I got it working first try.

I downloaded http://effbot.org/downloads/PIL-1.1.7.win32-py2.7.exe
ensured it was to correct path Python 2.7 and not python3.x
ran the exe
and import PIL without errors

Code: Select all
C:\>cd Python27

C:\Python27>python
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named PIL
>>> exit()

C:\Python27>cd ..

C:\>cd Users

C:\Users>cd metulburr

C:\Users\metulburr>cd Downloads

C:\Users\metulburr\Downloads>PIL-1.1.7.win32-py2.7.exe

C:\Users\metulburr\Downloads>cd ../..

C:\Users>cd ..

C:\>cd Python27

C:\Python27>python
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
>>>
New Users, Read This
OS Ubuntu 14.04, Arch Linux, Gentoo, Windows 7/8
https://github.com/metulburr
steam
User avatar
metulburr
 
Posts: 1471
Joined: Thu Feb 07, 2013 4:47 pm
Location: Elmira, NY

Re: Getting PIL to work on Windows 7, 64 bit

Postby casevh » Wed Feb 13, 2013 12:20 am

The issue with your install isn't that you have a 64-bit version of Windows, but that a 64-bit version of Windows can run either a 32-bit or 64-bit version of Python. If a library includes a compiled C module (and PIL does), then both Python and the library must match. The registry entries for Python are installed in different locations depending on whether the Python executable itself is 32 or 64 bits. If you had to move the registry keys around, then you had a mismatch between 32 and 64 bit versions.

HTH,
casevh
casevh
 
Posts: 70
Joined: Sat Feb 09, 2013 7:35 am

Re: Getting PIL to work on Windows 7, 64 bit

Postby SifJar » Wed Feb 13, 2013 9:12 am

metulburr wrote:In a fresh install of windows 7 in a virtual box after installing python2.7, I got it working first try.

I downloaded http://effbot.org/downloads/PIL-1.1.7.win32-py2.7.exe
ensured it was to correct path Python 2.7 and not python3.x
ran the exe
and import PIL without errors

Code: Select all
C:\>cd Python27

C:\Python27>python
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named PIL
>>> exit()

C:\Python27>cd ..

C:\>cd Users

C:\Users>cd metulburr

C:\Users\metulburr>cd Downloads

C:\Users\metulburr\Downloads>PIL-1.1.7.win32-py2.7.exe

C:\Users\metulburr\Downloads>cd ../..

C:\Users>cd ..

C:\>cd Python27

C:\Python27>python
Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win
32
Type "help", "copyright", "credits" or "license" for more information.
>>> import PIL
>>>


I can import it fine, and some functions work, it's only some functions that fail.

casevh wrote:The issue with your install isn't that you have a 64-bit version of Windows, but that a 64-bit version of Windows can run either a 32-bit or 64-bit version of Python. If a library includes a compiled C module (and PIL does), then both Python and the library must match. The registry entries for Python are installed in different locations depending on whether the Python executable itself is 32 or 64 bits. If you had to move the registry keys around, then you had a mismatch between 32 and 64 bit versions.

HTH,
casevh

Hmm. I was fairly sure I installed the 64 bit version. Although it was a while ago, so I may be remembering wrong. So is the solution to uninstall my current Python installation and install the 64-bit version, then install PIL?

I'm confused as to why some of PIL works, and so installing it clearly partially worked, but that one file is missing from the DLL folder...

EDIT: I checked the install, it's definitely the 64 bit version. Should I install the 32 bit version instead?

EDIT: Installed 32 bit version of Python, it's working fine now. Thanks for your help.
SifJar
 
Posts: 3
Joined: Tue Feb 12, 2013 11:04 pm

Re: Getting PIL to work on Windows 7, 64 bit

Postby casevh » Wed Feb 13, 2013 2:22 pm

You could have also installed the 64-bit version of PIL. The key in the name convention is the use of "amd64". Python installers that include "amd64" in their name include 64-bit Windows compiled libraries.

casevh
casevh
 
Posts: 70
Joined: Sat Feb 09, 2013 7:35 am

Re: Getting PIL to work on Windows 7, 64 bit

Postby SifJar » Fri Feb 15, 2013 4:03 pm

casevh wrote:You could have also installed the 64-bit version of PIL. The key in the name convention is the use of "amd64". Python installers that include "amd64" in their name include 64-bit Windows compiled libraries.

casevh

Well, the official PIL site doesn't seem to have a 64-bit version (although I have found it at another site). I'm guessing that in future I'm probably more likely to be able to find 32-bit versions of any troublesome libraries, so this is probably the best option anyway.

Thanks again for your help.
SifJar
 
Posts: 3
Joined: Tue Feb 12, 2013 11:04 pm


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot], W3C [Linkcheck] and 7 guests