PIL ImageTK not loading image in py2app application bundle

隐身守侯 提交于 2020-01-02 03:50:28

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/33302918/pil-imagetk-not-loading-image-in-py2app-application-bundle

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