Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python py2exe给出运行时错误:创建映像太早_Python_Tkinter_Py2exe_Photoimage - Fatal编程技术网

Python py2exe给出运行时错误:创建映像太早

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 <

这个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 <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

当所有其他操作都失败时,请重建所有内容

  • 卸载32位python27.12
  • 安装32位python27.10//12可能也可以
  • 安装pip
  • pip安装枕
  • 安装MSVC9
  • pip安装py2exe
  • 从旧版py2exe中删除所有以前的分发版本
  • 重新生成可执行文件

  • 它起作用了

    尝试将枕头向后滚动几个版本,停止在2.5。。。不走运