Python py2exe给出运行时错误:创建映像太早
这个python27 32位代码在空闲状态下运行得非常好,但是当用py2exe打包时。。。不太好。这不是缺失的Tk()问题的重复。在运行py2exe生成的可执行文件时,似乎还有一些未初始化的内容,在ImageTk.PhotoImage()上的调用会遇到“创建映像太早”的问题:Python py2exe给出运行时错误:创建映像太早,python,tkinter,py2exe,photoimage,Python,Tkinter,Py2exe,Photoimage,这个python27 32位代码在空闲状态下运行得非常好,但是当用py2exe打包时。。。不太好。这不是缺失的Tk()问题的重复。在运行py2exe生成的可执行文件时,似乎还有一些未初始化的内容,在ImageTk.PhotoImage()上的调用会遇到“创建映像太早”的问题: C:\python\python_ui\exe\dist>basic.exe Traceback (most recent call last): File "basic.py", line 7, in <
C:\python\python_ui\exe\dist>basic.exe
Traceback (most recent call last):
File "basic.py", line 7, in <module>
File "PIL\ImageTk.pyo", line 117, in __init__
File "Tkinter.pyo", line 3367, in __init__
File "Tkinter.pyo", line 3304, in __init__
RuntimeError: Too early to create image
Exception AttributeError: "'PhotoImage' object has no attribute '_PhotoImage__photo'" in <bound method PhotoImage.__del__ of <PIL.ImageTk.Ph
otoImage object at 0x02CA3A90>> ignored
setup.py-这是我的py2exe安装程序,我运行python setup.py py2exe
获取可执行文件:
import py2exe, sys, os
from distutils.core import setup
from glob import glob
sys.path.append("C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\redist\\x86\\Microsoft.VC90.CRT")
sys.argv.append('py2exe')
setup(
data_files = [
("Microsoft.VC90.CRT", glob(r'C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*')),
("background.jpg"),
],
options = {
'py2exe' : {
'compressed': 1,
'optimize': 2,
'bundle_files': 3,
'dist_dir': 'dist',
'dll_excludes': ["MSVCP90.dll"]
}
},
zipfile=None,
console = [{'script':'user_code.py'}, {'script':'basic.py'}],
)
版本信息匹配,从IDLE()运行时,打印图像会给出与可执行文件相同的值:
import py2exe, sys, os
from distutils.core import setup
from glob import glob
sys.path.append("C:\\Program Files\\Microsoft Visual Studio 9.0\\VC\\redist\\x86\\Microsoft.VC90.CRT")
sys.argv.append('py2exe')
setup(
data_files = [
("Microsoft.VC90.CRT", glob(r'C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT\*.*')),
("background.jpg"),
],
options = {
'py2exe' : {
'compressed': 1,
'optimize': 2,
'bundle_files': 3,
'dist_dir': 'dist',
'dll_excludes': ["MSVCP90.dll"]
}
},
zipfile=None,
console = [{'script':'user_code.py'}, {'script':'basic.py'}],
)
- pil 3.4.2
- tkinter$修订版:81008$
- PIL.JpegImagePlugin.JpegImageFile图像模式=RGB大小=179x119,0x3DF6A50
它起作用了 尝试将枕头向后滚动几个版本,停止在2.5。。。不走运