【发布时间】:2014-07-17 07:43:05
【问题描述】:
我使用 Python 2 编写的代码在从 Python 运行时运行良好,但在我通过 PyInstaller 发送脚本并运行可执行文件后,它会吐出:
Traceback (most recent call last):
File "<string>", line 26, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/ben/Documents/Programming/Python/Weasyl/Test Scripts/build/test3/out00-PYZ.pyz/PIL.PngImagePlugin", line 40, in <module>
File "/usr/local/lib/python2.7/dist-packages/PyInstaller/loader/pyi_importers.py", line 270, in load_module
exec(bytecode, module.__dict__)
File "/home/ben/Documents/Programming/Python/Weasyl/Test Scripts/build/test3/out00-PYZ.pyz/PIL.Image", line 53, in <module>
ImportError: cannot import name _imaging
我不完全确定为什么在导入这个模块时会出现问题,因为 PyInstaller 将 Tkinter 和 PIL 列为兼容的。整个代码如下:
#!/usr/bin/env python
from Tkinter import *
from PIL import ImageTk, Image
import os
root = Tk()
name = Label(root, text="(username)", font="Arial 20")
name.grid(row=0, column=0)
status = Label(root, text="(login status)")
status.grid(row=1, column=0)
img = ImageTk.PhotoImage(Image.open(".avatar.png"))
panel = Label(root, image=img, relief=RAISED, height=100, width=100)
panel.grid(row=0, column=1, columnspan=2, rowspan=2)
root.mainloop()
我假设问题出在from PIL import ImageTk, Image 上,但没有办法使用该模块,因为我要使用的图像是 PNG 格式,据我所知,Tkinter 仅支持 GIF 格式之外使用那个模块。
编辑:如果我不能将此模块与 PyInstaller 一起使用,有没有办法让 PNG 图像在此模块之外的 Tkinter 中显示?
【问题讨论】:
标签: python tkinter python-imaging-library pyinstaller