[Pythonmac-SIG] PIL and py2app on Leopard
Christopher Barker
Chris.Barker at noaa.gov
Wed Apr 9 19:22:05 CEST 2008
Sorry, I've lost track of this thread a bit, but I'm going to try to
give some general advice -- sorry if I repeat stuff you've already
said/tried:
>> import Image
>
> that throws an error that the module is not found even without wrapping
> is it the recommendation for py2app or for python general?
Yes, that is how PIL is usually imported, so you'll have an easier time
getting your install fixed first. Indeed, when I started using PIL,
"import Image" was the only option.
I've just looked at my install, which is from the PIL package on
pythonmac.org/packages. in site-packages, there is a directory called
"PIL". It is a package (it has an __init__.py), but it is also added to
the sys.path by the addition of a PIL.pth file. So you should be able to
import it either way, but perhaps "from PIL import Image" is confusing
py2app.
>> This requires that PYTHONPATH is set up to find the module.
not quite -- just to get the terminology straight -- PYTHONPATH is an
environment variable in which one can specify additional paths you want
Python to search for packages/modules.
sys.path is the set of paths used by python to find stuff -- it is built
at initialization from a number of sources, of which PYTHONPATH is only
one. In addition, you can add paths to sys.path yourself, in your code,
at runtime.
I've never had a need to use PYTHONPATH, and I don't recommend it --
Environment variables are different depending on how your script is run,
and there is only one PYTHONPATH, even though there may be multiple
version of python on your system.
> obviously it is missing how do I add it?
Odd -- how did you install PIL? Anyway, there should be a file in
/Library/Python/2.5/site-packages
called "PIL.pth", and in there, should be the single line" "PIL". This
assumes that PIL is installed in:
/Library/Python/2.5/site-packages/PIL
That should add it to your path.
Now on to py2app:
Py2app is supposed to read your code and determine what modules/packages
are needed, an include those automatically. Some packages need special
attention to be included correctly. PIL is one of those. In this case,
there are built-in "recipes" that should get triggered when you use a
given package, and it will do some extra stuff for you. There is a PIL
recipe in:
/Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/site-packages/py2app-0.4.2-py2.5.egg/py2app/recipes/PIL
That should "do the right thing" with PIL.
If it isn't working, then it's broken, and hopefully one of the folks
here can figure it out and fix it.
So, for your situation, I recommend:
1) Get PIL installed so that "import Image" works.
2) make a little script that does little else but "import image" and
some little action to test it.
3) build a simple py2app setup.py, like:
from setuptools import setup
setup(
app="MyScript.py",
setup_requires=['py2app'],
)
Should do it.
And you might want to try it with both: "import Image" and "from PIL
import Image", 'cause it looks like both should work.
That should "just work". If it doesn't:
Report back what you get, and be sure to include:
Your script
Your setup.py
Your OS-X version
Your Python version (where you got it, how you installed it)
Your py2app version
Your PIL version (where you got it, how you installed it)
-Chris
--
Christopher Barker, Ph.D.
Oceanographer
Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception
Chris.Barker at noaa.gov
More information about the Pythonmac-SIG
mailing list