PIL ImageTK not loading image in py2app application bundle
Asked Answered
B

1

6

I'm testing out an app that I've made which, amongst other things, loads a couple of .png images when opened. The images are displayed correctly on my Mac (10.7.5) and my mother's (10.8.5); however when my sister opens it on hers (10.9.5) the images don't load. All other functionality is otherwise intact. I should note that on my Mac and my mother's, I installed Python 3.4 and many of the packages that the app uses, including the PIL package, whereas my sister has none of these. The app was build using the command:

python3.4 setup.py py2app

Images are imported in the code with:

image = ImageTk.PhotoImage(file = "images/pic.png")

Setup file for py2app is as follows:

from setuptools import setup

APP = ['myapp.py']
DATA_FILES = [('', ['images'])]

OPTIONS = {'iconfile': 'myapp.icns', 'packages': ['PIL']}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

My guess is that it's an issue with PIL, it just doesn't seem to want to play nicely with py2app. The reason I think it's PIL is because after running the command to build my app I get the following error message in Terminal.

Modules not found (conditional imports):
* Image (/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/py2app/recipes/PIL/prescript.py)

I'd be very grateful for any suggestions or direction.

Baboon answered 23/10, 2015 at 12:57 Comment(2)
I am getting the same error and I will post here if i find anythingDraughts
if you are installing Image from the Pillow library the way you should install it is from PIL import Image. Your sister's computer most likely has a more recent version of python so this is hence the way to install it, any other way would throw an errorPym
P
0

If you are building a python package that requires other packages to be installed, you can use the install_requires keyword within setup see docs. This has the additional benefit of installing the package(s) when the user runs pip install py2app. In your case I would use install_requires=['pillow'] and pip will automagically grab pillow during the installation process.

Pleurodynia answered 21/6, 2017 at 0:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.