How to install PIL on Mac OSX 10.5.8 for Google App Engine?

左心房为你撑大大i 提交于 2020-01-27 15:37:05

问题


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.


回答1:


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




回答2:


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.




回答3:


Give Pillow a try.

pip install Pillow

... and that's it.




回答4:


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.




回答5:


sudo port install py27-pil
pip install pil



回答6:


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.




回答7:


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




回答8:


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.



来源:https://stackoverflow.com/questions/4868185/how-to-install-pil-on-mac-osx-10-5-8-for-google-app-engine

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!