PIL ImageTK未在py2app应用程序捆绑包中加载图像 [英] PIL ImageTK not loading image in py2app application bundle
问题描述
我正在测试一个我制作的应用程序,除其他外,该应用程序在打开时会加载几个.png图像.图像在我的Mac(10.7.5)和我的母亲(10.8.5)上正确显示;但是,当我姐姐在她的姐姐(10.9.5)上打开它时,图像不会加载.否则,所有其他功能均完好无损.我应该注意,在我的Mac和我的Mac上,我安装了Python 3.4和该应用程序使用的许多软件包,包括PIL软件包,而我的妹妹则没有.该应用是使用以下命令构建的:
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")
py2app的安装文件如下:
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'],
)
我的猜测是PIL是一个问题,它似乎并不想与py2app完美配合.我认为它是PIL的原因是因为在运行命令以构建我的应用程序后,我在终端中收到以下错误消息.
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.
推荐答案
如果要构建需要安装其他软件包的python软件包,则可以在安装程序
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.
这篇关于PIL ImageTK未在py2app应用程序捆绑包中加载图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!