19

I need to get PIL installed locally to test GAE's images api in my local environment.

I grabbed the PIL 1.1.6 installer for Mac, and when I go to select the destination (when installing), I get the error:

You cannot install PIL 1.1.6 on this volume. 
PIL requires System Python 2.5 to install.

I have Python 2.5.x on this machine.

NOTE:

Added a bounty. I am in real need of a way to test the image API locally on my Mac.

Will Curran
  • 6,959
  • 15
  • 59
  • 92
  • Is it your own install or the system's version of python? Did you try these PIL and Python versions: http://pythonmac.org/packages/py25-fat/index.html. Also see this http://stackoverflow.com/questions/1774825/unable-to-use-pil-after-installing-using-pythononmac-org-package-mac-os-leopard – Benjamin Feb 01 '11 at 21:35
  • +1 - Had similar woes trying to install PIL on Mac OS X, hope a good solution shows up. – ocodo Feb 01 '11 at 21:35
  • Good question. I am not sure. How can I check? Is "System Python" referring to the version bundled with Mac OSX? – Will Curran Feb 01 '11 at 21:37
  • Why aren't you using easy_install or pip? – Piotr Duda Feb 01 '11 at 22:00
  • I tried installing via MacPort and that failed too. What's easy_install? – Will Curran Feb 01 '11 at 22:33
  • 1
    easy_install aka setup tools http://pypi.python.org/pypi/setuptools – Benjamin Feb 01 '11 at 23:08
  • @Will Merydith: to find out which version of Python you're using, type `which python`, and this will give the install path for the current default python. It's recommended to not use the system one, so your path should probably say something like /Library/Frameworks/Python.framework/Versions/2.6/bin/python (or whatever verson of Python you want to use if not 2.6). – tom10 Apr 02 '11 at 04:59

8 Answers8

20

That's quite easy:

  1. Install MacPorts
  2. Install Python 2.5 with sudo port install python25
  3. Install Pil for Python 2.5 with sudo port install py25-pil
  4. In the Google App Engine launcher Preferences set /opt/local/bin/python2.5 as Python Path *
  5. Restart the Google App Engine launcher
  6. Happy coding

* be sure to confirm it with an ENTER or it will not persist

systempuntoout
  • 71,966
  • 47
  • 171
  • 241
  • I was hoping it'd be that easy but GAE is not finding PIL. "nable to find the Python PIL library. Please view the SDK documentation for details about installing PIL on your system." – Will Curran Apr 01 '11 at 19:22
  • @Will what do you see in Google App Engine launcher Preferences? – systempuntoout Apr 01 '11 at 19:23
  • @Will as I said it's quite easy. – systempuntoout Apr 02 '11 at 11:46
  • When I open the preferences I see no entry, but then I can set it to the path you list above. But it doesn't persist. So maybe that path is not valid on my Mac, let me check that out. – Will Curran Apr 04 '11 at 14:49
  • @Will no, it's a UI flaw. You need to confirm with an ENTER or it will not persist. Set it as I said. – systempuntoout Apr 04 '11 at 15:07
  • 2
    That worked! Hopefully other developers will easily find this post and you instructions! – Will Curran Apr 05 '11 at 17:28
  • Notes: I had to restart googleappenginelauncher before it worked. Also, MacPorts install did not work with the DMG file on the site for Snow Leopard, but had to install from source (which worked painlessly though). – Bemmu Apr 27 '11 at 09:48
  • 2
    I think google should update their wiki page on installing the PIL library to this simple steps... it just works! – samiq Jul 18 '11 at 06:17
  • 1
    If you're upgrading to python 2.7 you can use similar steps: $ sudo port install py27-pil in App Engine launcher set the python path to /opt/local/bin/python2.7 – mckoss Sep 04 '12 at 16:26
5

I would install homebrew, and use that to install python2.7 (a requirement for pip to work properly together with homebrew) and then use pip to install PIL.

If you don't have macports or fink or something installed already, this is simple. If you do, you might want to look into removing it first (especially if they live in /usr/local).

Installing homebrew: https://github.com/mxcl/homebrew/wiki/Installation

(If you have Xcode installed (you need a compiler) you can just use this one-liner, but I recommend you read the instructions first so you understand what it does.)

ruby -e "$(curl -fsSLk https://gist.github.com/raw/323731/install_homebrew.rb)"

Installing python 2.7:

brew install python

Just remember to add the homebrew python as well as your homebrew bin directory to the front of your $PATH after installing (put this in your ~/.bashrc):

export PATH=/usr/local/bin:/usr/local/Cellar/python/2.7.1/bin:$PATH

Installing PIL: (it seems like my installation is linked against libjpeg, so install that first)

brew install jpeg
pip install pil

There you go.

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
oyvindio
  • 797
  • 5
  • 10
3

Give Pillow a try.

pip install Pillow

... and that's it.

bradley.ayers
  • 37,165
  • 14
  • 93
  • 99
2

Here is another method that does not require macports or homebrew, etc... http://cgarvey.ie/blog/archive/2010/01/27/installing-pil-on-mac-os-x-snow-leopard-for-use-in-google-app-engine/

It says snow leopard in the title, but it works fine on leopard (just did this). Paraphrased from the article:

  1. Download jpegsrc.v8c.tar.gz or the latest from http://www.ijg.org/files/
  2. Extract jpegsrc and from within that directory:

    export CC="gcc -arch i386"
    ./configure
    make
    sudo make install

  3. Download and extract PIL and from within the PIL directory

    sudo python setup.py install

This seems to be working for me so hopefully it helps someone else.

Sorry that the formatting is a little bit weird but I'm having some trouble with the editor.

joshcartme
  • 2,717
  • 1
  • 22
  • 34
2
sudo port install py27-pil
pip install pil
EdChum
  • 376,765
  • 198
  • 813
  • 562
1

As stated in my comment, I have installed and tested the Python and PIL installations found here and everything works fine. Your error is likely related to trying to use the system version of Python.

Benjamin
  • 11,560
  • 13
  • 70
  • 119
  • So do I need to first install the Python package found in that link? Will that interfere with my GAE installation? – Will Curran Feb 01 '11 at 22:32
0

I've had python2.7 and PIL installed for a long time (using MacPorts) and I've been using them successfully in non-app-engine work. App Engine failed to load it and logged the following message:

Could not initialize images API; you are likely missing the Python "PIL" module.

Inspired by @DaveGallagher's comment above about MacPorts installing into /opt/local/..., I realized I wasn't running the right python. In "Google App Engine Launcher", in "Preferences...", I changed "Python Path" to

/opt/local/bin/python2.7

Now, when I run, it finds PIL and the images service works.

ps. i'm running GAE Launcher 1.8.2.978.

0

I don't have 10.5.8 to test this, so YMMV (works on 10.6):

  1. Install MacPorts (Leopard version): http://www.macports.org/install.php
  2. Applications -> Utilities -> Terminal
  3. $ sudo port install python27
  4. $ sudo port install py27-pip

Install PIL either via MacPorts or pip (whichever works - DON'T RUN BOTH):

  • $ sudo port install py27-pil
  • $ sudo pip-2.7 install PIL

Launch Python 2.7 and test it out:

$ python2.7
>>> import PIL
>>> PIL
<module 'PIL' from '/opt/local/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/PIL/__init__.pyc'>

Remember, you have to type $ python2.7, since $ python will continue to load the OS X version of Python, which is 2.5 I believe...

This means any scripts you write with #!/usr/bin/env python at the top will use the non-PIL Python 2.5. You'll have to change them to #!/opt/local/bin/python2.7 for PIL-Python 2.7. Or...

You can easily change whichever Python version $ python loads, and ignore that header madness, by installing python_select:

$ sudo port install python_select
...installs stuff...
$ sudo python_select python27

Now, whenever you run $ python, it'll load Python 2.7, and not OS X Python 2.5. You can easily switch back anytime. Just run $ python_select -l and you'll see the -apple version of Python. On 10.6: $ sudo python_select python26-apple

Dave
  • 12,408
  • 12
  • 64
  • 67
  • This worked well and I got PIL installed, but Google App Engine doesn't see it: WARNING 2011-03-31 03:37:39,566 dev_appserver.py:3700] Could not initialize images API; you are likely missing the Python "PIL" module. ImportError: No module named _imaging – Will Curran Mar 31 '11 at 03:51
  • MacPorts actually installs a separate copy of Python, different than Mac OS X's. All MacPorts stuff lives inside /opt/local/... They do this to keep things separated from OS X (keeps MacPorts from breaking OS X, and vice versa). So basically, your copy of Google App Engine is likely installed using Apple's version of Python (happens if you run Googles installer). You'll have to install it for MacPort's Python via `sudo port install py27-googleappengine`. Then you should be able to `python2.7`, and then import it. – Dave Mar 31 '11 at 14:44