Kivy Window.size:[警告] stderr:AttributeError:'NoneType'对象没有属性'size'

时间:2019-07-13 17:32:57

标签: python kivy pyinstaller

从PyCharm运行我的代码时,该应用程序可以完美运行,如下面的日志所述:

[INFO   ] Logger: Record log in C:\Users\gomes\.kivy\logs\kivy_19-07-13_125.txt
[INFO   ] deps: Successfully imported "kivy_deps.gstreamer" 0.1.17
[INFO   ] deps: Successfully imported "kivy_deps.angle" 0.1.9
[INFO   ] deps: Successfully imported "kivy_deps.glew" 0.1.12
[INFO   ] deps: Successfully imported "kivy_deps.sdl2" 0.1.22
[INFO   ] Kivy: v1.11.1
[INFO   ] Kivy: Installed at "C:\Users\gomes\Anaconda3\envs\k36\lib\site-packages\kivy\__init__.py"
[INFO   ] Python: v3.6.8 |Anaconda, Inc.| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]
[INFO   ] Python: Interpreter at "C:\Users\gomes\Anaconda3\envs\k36\python.exe"
[INFO   ] Factory: 184 symbols loaded
[INFO   ] Image: Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
[INFO   ] Text: Provider: sdl2
[INFO   ] Window: Provider: sdl2
[INFO   ] GL: Using the "OpenGL" graphics system
[INFO   ] GL: GLEW initialization succeeded
[INFO   ] GL: Backend used <glew>
[INFO   ] GL: OpenGL version <b'4.4.0 - Build 22.20.16.4691'>
[INFO   ] GL: OpenGL vendor <b'Intel'>
[INFO   ] GL: OpenGL renderer <b'Intel(R) HD Graphics 630'>
[INFO   ] GL: OpenGL parsed version: 4, 4
[INFO   ] GL: Shading version <b'4.40 - Build 22.20.16.4691'>
[INFO   ] GL: Texture max size <16384>
[INFO   ] GL: Texture max units <32>
[INFO   ] Window: auto add sdl2 input provider
[INFO   ] Window: virtual keyboard not allowed, single mode, not docked
[INFO   ] GL: NPOT texture support is available
[INFO   ] Base: Start application main loop

但是当我将其与Pyinstaller打包到单个文件.exe中时,它将无法正常工作并显示以下日志:

[INFO   ] Logger: Record log in C:\Users\gomes\.kivy\logs\kivy_19-07-13_124.txt
[INFO   ] Kivy: v1.11.1
[INFO   ] Kivy: Installed at "C:\Users\gomes\AppData\Local\Temp\_MEI52922\kivy\__init__.pyc"
[INFO   ] Python: v3.6.8 |Anaconda, Inc.| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]
[INFO   ] Python: Interpreter at "c:\registros\dist\Registros Periciais 1.2.exe"
[INFO   ] Factory: 184 symbols loaded
[DEBUG  ] Cache: register <kv.lang> with limit=None, timeout=None
[DEBUG  ] Cache: register <kv.image> with limit=None, timeout=60
[DEBUG  ] Cache: register <kv.atlas> with limit=None, timeout=None
[INFO   ] Image: Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
[DEBUG  ] Cache: register <kv.texture> with limit=1000, timeout=60
[DEBUG  ] Cache: register <kv.shader> with limit=1000, timeout=3600
[INFO   ] Text: Provider: sdl2
[INFO   ] Window: Provider: sdl2
[INFO   ] GL: Using the "OpenGL" graphics system
[INFO   ] GL: GLEW initialization succeeded
[DEBUG  ] GL: available extensions: b'GL_3DFX_texture_compression_FXT1 GL_AMD_depth_clamp_separate GL_AMD_vertex_shader_layer GL_AMD_vertex_shader_viewport_index GL_ARB_ES2_compatibility GL_ARB_ES3_1_compatibility GL_ARB_ES3_compatibility GL_ARB_arrays_of_arrays GL_ARB_base_instance GL_ARB_bindless_texture GL_ARB_blend_func_extended GL_ARB_buffer_storage GL_ARB_cl_event GL_ARB_clear_buffer_object GL_ARB_clear_texture GL_ARB_clip_control GL_ARB_color_buffer_float GL_ARB_compatibility GL_ARB_compressed_texture_pixel_storage GL_ARB_compute_shader GL_ARB_conditional_render_inverted GL_ARB_conservative_depth GL_ARB_copy_buffer GL_ARB_copy_image GL_ARB_cull_distance GL_ARB_debug_output GL_ARB_depth_buffer_float GL_ARB_depth_clamp GL_ARB_depth_texture GL_ARB_derivative_control GL_ARB_draw_buffers GL_ARB_draw_buffers_blend GL_ARB_draw_elements_base_vertex GL_ARB_draw_indirect GL_ARB_draw_instanced GL_ARB_enhanced_layouts GL_ARB_explicit_attrib_location GL_ARB_explicit_uniform_location GL_ARB_fragment_coord_conventions GL_ARB_fragment_layer_viewport GL_ARB_fragment_program GL_ARB_fragment_program_shadow GL_ARB_fragment_shader GL_ARB_fragment_shader_interlock GL_ARB_framebuffer_no_attachments GL_ARB_framebuffer_object GL_ARB_framebuffer_sRGB GL_ARB_geometry_shader4 GL_ARB_get_program_binary GL_ARB_get_texture_sub_image GL_ARB_gpu_shader5 GL_ARB_gpu_shader_fp64 GL_ARB_half_float_pixel GL_ARB_half_float_vertex GL_ARB_indirect_parameters GL_ARB_instanced_arrays GL_ARB_internalformat_query GL_ARB_internalformat_query2 GL_ARB_invalidate_subdata GL_ARB_map_buffer_alignment GL_ARB_map_buffer_range GL_ARB_multi_bind GL_ARB_multi_draw_indirect GL_ARB_multisample GL_ARB_multitexture GL_ARB_occlusion_query GL_ARB_occlusion_query2 GL_ARB_pixel_buffer_object GL_ARB_point_parameters GL_ARB_point_sprite GL_ARB_post_depth_coverage GL_ARB_program_interface_query GL_ARB_provoking_vertex GL_ARB_query_buffer_object GL_ARB_robust_buffer_access_behavior GL_ARB_robustness GL_ARB_robustness_isolation GL_ARB_sample_shading GL_ARB_sampler_objects GL_ARB_seamless_cube_map GL_ARB_seamless_cubemap_per_texture GL_ARB_separate_shader_objects GL_ARB_shader_atomic_counters GL_ARB_shader_bit_encoding GL_ARB_shader_draw_parameters GL_ARB_shader_image_load_store GL_ARB_shader_image_size GL_ARB_shader_objects GL_ARB_shader_precision GL_ARB_shader_stencil_export GL_ARB_shader_storage_buffer_object GL_ARB_shader_subroutine GL_ARB_shader_texture_image_samples GL_ARB_shading_language_100 GL_ARB_shading_language_420pack GL_ARB_shading_language_packing GL_ARB_shadow GL_ARB_stencil_texturing GL_ARB_sync GL_ARB_tessellation_shader GL_ARB_texture_barrier GL_ARB_texture_border_clamp GL_ARB_texture_buffer_object_rgb32 GL_ARB_texture_buffer_range GL_ARB_texture_compression GL_ARB_texture_compression_bptc GL_ARB_texture_compression_rgtc GL_ARB_texture_cube_map GL_ARB_texture_cube_map_array GL_ARB_texture_env_add GL_ARB_texture_env_combine GL_ARB_texture_env_crossbar GL_ARB_texture_env_dot3 GL_ARB_texture_float GL_ARB_texture_gather GL_ARB_texture_mirror_clamp_to_edge GL_ARB_texture_mirrored_repeat GL_ARB_texture_multisample GL_ARB_texture_non_power_of_two GL_ARB_texture_query_levels GL_ARB_texture_query_lod GL_ARB_texture_rectangle GL_ARB_texture_rg GL_ARB_texture_rgb10_a2ui GL_ARB_texture_stencil8 GL_ARB_texture_storage GL_ARB_texture_storage_multisample GL_ARB_texture_swizzle GL_ARB_texture_view GL_ARB_timer_query GL_ARB_transform_feedback2 GL_ARB_transform_feedback3 GL_ARB_transform_feedback_instanced GL_ARB_transpose_matrix GL_ARB_uniform_buffer_object GL_ARB_vertex_array_bgra GL_ARB_vertex_array_object GL_ARB_vertex_attrib_64bit GL_ARB_vertex_attrib_binding GL_ARB_vertex_buffer_object GL_ARB_vertex_program GL_ARB_vertex_shader GL_ARB_vertex_type_10f_11f_11f_rev GL_ARB_vertex_type_2_10_10_10_rev GL_ARB_viewport_array GL_ARB_window_pos GL_ATI_separate_stencil GL_EXT_abgr GL_EXT_bgra GL_EXT_blend_color GL_EXT_blend_equation_separate GL_EXT_blend_func_separate GL_EXT_blend_minmax GL_EXT_blend_subtract GL_EXT_clip_volume_hint GL_EXT_compiled_vertex_array GL_EXT_direct_state_access GL_EXT_draw_buffers2 GL_EXT_draw_range_elements GL_EXT_fog_coord GL_EXT_framebuffer_blit GL_EXT_framebuffer_multisample GL_EXT_framebuffer_object GL_EXT_geometry_shader4 GL_EXT_gpu_program_parameters GL_EXT_gpu_shader4 GL_EXT_multi_draw_arrays GL_EXT_packed_depth_stencil GL_EXT_packed_float GL_EXT_packed_pixels GL_EXT_polygon_offset_clamp GL_EXT_rescale_normal GL_EXT_secondary_color GL_EXT_separate_specular_color GL_EXT_shader_framebuffer_fetch GL_EXT_shader_integer_mix GL_EXT_shadow_funcs GL_EXT_stencil_two_side GL_EXT_stencil_wrap GL_EXT_texture3D GL_EXT_texture_array GL_EXT_texture_compression_s3tc GL_EXT_texture_edge_clamp GL_EXT_texture_env_add GL_EXT_texture_env_combine GL_EXT_texture_filter_anisotropic GL_EXT_texture_integer GL_EXT_texture_lod_bias GL_EXT_texture_rectangle GL_EXT_texture_sRGB GL_EXT_texture_sRGB_decode GL_EXT_texture_shared_exponent GL_EXT_texture_snorm GL_EXT_texture_storage GL_EXT_texture_swizzle GL_EXT_timer_query GL_EXT_transform_feedback GL_IBM_texture_mirrored_repeat GL_INTEL_conservative_rasterization GL_INTEL_fragment_shader_ordering GL_INTEL_framebuffer_CMAA GL_INTEL_map_texture GL_INTEL_multi_rate_fragment_shader GL_INTEL_performance_query GL_KHR_blend_equation_advanced GL_KHR_blend_equation_advanced_coherent GL_KHR_context_flush_control GL_KHR_debug GL_KHR_texture_compression_astc_hdr GL_KHR_texture_compression_astc_ldr GL_NV_blend_square GL_NV_conditional_render GL_NV_primitive_restart GL_NV_texgen_reflection GL_SGIS_generate_mipmap GL_SGIS_texture_edge_clamp GL_SGIS_texture_lod GL_SUN_multi_draw_arrays GL_WIN_swap_hint'
[DEBUG  ] GL: glShaderBinary is not available
[INFO   ] GL: Backend used <glew>
[INFO   ] GL: OpenGL version <b'4.4.0 - Build 22.20.16.4691'>
[INFO   ] GL: OpenGL vendor <b'Intel'>
[INFO   ] GL: OpenGL renderer <b'Intel(R) HD Graphics 630'>
[INFO   ] GL: OpenGL parsed version: 4, 4
[INFO   ] GL: Shading version <b'4.40 - Build 22.20.16.4691'>
[INFO   ] GL: Texture max size <16384>
[INFO   ] GL: Texture max units <32>
[DEBUG  ] Shader: Fragment compiled successfully
[DEBUG  ] Shader: Vertex compiled successfully
[DEBUG  ] ImageSDL2: Load <C:\Users\gomes\AppData\Local\Temp\_MEI52922\kivy_install\data\glsl\default.png>
[WARNING] Image: Unable to load image <C:\Users\gomes\AppData\Local\Temp\_MEI52922\kivy_install\data\glsl\default.png>
[CRITICAL] Window: Unable to find any valuable Window provider. Please enable debug logging (e.g. add -d if running from the command line, or change the log level in the config) and re-run your app to identify potential causes
sdl2 - Exception: SDL2: Unable to load image
  File "site-packages\kivy\core\__init__.py", line 71, in core_select_lib
  File "site-packages\kivy\core\window\window_sdl2.py", line 152, in __init__
  File "site-packages\kivy\core\window\__init__.py", line 981, in __init__
  File "site-packages\kivy\core\window\window_sdl2.py", line 312, in create_window
  File "site-packages\kivy\core\window\__init__.py", line 1258, in create_window
  File "kivy\graphics\instructions.pyx", line 783, in kivy.graphics.instructions.RenderContext.__init__
  File "site-packages\kivy\core\image\__init__.py", line 561, in __init__
  File "site-packages\kivy\core\image\__init__.py", line 756, in _set_filename
  File "site-packages\kivy\core\image\__init__.py", line 460, in load
  File "site-packages\kivy\core\image\__init__.py", line 223, in __init__
  File "site-packages\kivy\core\image\img_sdl2.py", line 47, in load

[DEBUG  ] Cache: register <textinput.label> with limit=None, timeout=60.0
[DEBUG  ] Cache: register <textinput.width> with limit=None, timeout=60.0
[WARNING] stderr: Traceback (most recent call last):
[WARNING] stderr:   File "main1.2.py", line 24, in <module>
[WARNING] stderr: AttributeError: 'NoneType' object has no attribute 'size'

应用代码(导入和错误行)

import kivy
kivy.require('1.11.1')
from kivy.app import App
from kivy.uix.spinner import Spinner
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.button import Button
from kivy.core.window import Window
from kivy.uix.textinput import TextInput
from kivy.uix.image import Image
from kivy.uix.label import Label
from kivy.uix.popup import Popup
from kivy.uix.checkbox import CheckBox
Window.size = 500, 600

第24行,错误指向:

Window.size = 500, 600

试图删除Window.size行,这创建了另一个错误,表示该应用程序没有窗口。

[INFO   ] Logger: Record log in C:\Users\gomes\.kivy\logs\kivy_19-07-13_112.txt
[INFO   ] Kivy: v1.11.1
[INFO   ] Kivy: Installed at "C:\Users\gomes\AppData\Local\Temp\_MEI92402\kivy\__init__.pyc"
[INFO   ] Python: v3.6.8 |Anaconda, Inc.| (default, Feb 21 2019, 18:30:04) [MSC v.1916 64 bit (AMD64)]
[INFO   ] Python: Interpreter at "C:\registros\dist\Registros Periciais 1.2.exe"
[INFO   ] Factory: 184 symbols loaded
[INFO   ] Image: Providers: img_tex, img_dds, img_sdl2, img_gif (img_pil, img_ffpyplayer ignored)
[INFO   ] Text: Provider: sdl2
[INFO   ] Window: Provider: sdl2
[INFO   ] GL: Using the "OpenGL" graphics system
[INFO   ] GL: GLEW initialization succeeded
[INFO   ] GL: Backend used <glew>
[INFO   ] GL: OpenGL version <b'4.4.0 - Build 22.20.16.4691'>
[INFO   ] GL: OpenGL vendor <b'Intel'>
[INFO   ] GL: OpenGL renderer <b'Intel(R) HD Graphics 630'>
[INFO   ] GL: OpenGL parsed version: 4, 4
[INFO   ] GL: Shading version <b'4.40 - Build 22.20.16.4691'>
[INFO   ] GL: Texture max size <16384>
[INFO   ] GL: Texture max units <32>
[WARNING] Image: Unable to load image <C:\Users\gomes\AppData\Local\Temp\_MEI92402\kivy_install\data\glsl\default.png>
[CRITICAL] Window: Unable to find any valuable Window provider. Please enable debug logging (e.g. add -d if running from the command line, or change the log level in the config) and re-run your app to identify potential causes
sdl2 - Exception: SDL2: Unable to load image
  File "site-packages\kivy\core\__init__.py", line 71, in core_select_lib
  File "site-packages\kivy\core\window\window_sdl2.py", line 152, in __init__
  File "site-packages\kivy\core\window\__init__.py", line 981, in __init__
  File "site-packages\kivy\core\window\window_sdl2.py", line 312, in create_window
  File "site-packages\kivy\core\window\__init__.py", line 1258, in create_window
  File "kivy\graphics\instructions.pyx", line 783, in kivy.graphics.instructions.RenderContext.__init__
  File "site-packages\kivy\core\image\__init__.py", line 561, in __init__
  File "site-packages\kivy\core\image\__init__.py", line 756, in _set_filename
  File "site-packages\kivy\core\image\__init__.py", line 460, in load
  File "site-packages\kivy\core\image\__init__.py", line 223, in __init__
  File "site-packages\kivy\core\image\img_sdl2.py", line 47, in load

[CRITICAL] App: Unable to get a Window, abort.

在旧版本的Python / Kivy(3.6和1.10)中,同样的代码也可以正常工作。我现在刚刚再次将所有内容下载到另一台计算机上,最新的python 3.7.3,Kivy 1.11.1,pyinstaller v3.5,并且代码正在执行此操作。

此外,尽管未显示错误,但仍从PyCharm运行,无法正确呈现。 我有应用程序主窗口。然后按下按钮,将打开一个弹出窗口。使用完其内容后,将按下一个按钮popup.dismiss(),并再次弹出主窗口,但是在其背景中(而不是纯黑色),它将弹出内容作为背景进行贴花,而不是纯黑色,当另一个弹出菜单出现时,它将变为黑色打开。

主窗口/菜单

弹出菜单正常工作

popup.dismiss()带我回到这个奇怪的渲染窗口

1 个答案:

答案 0 :(得分:1)

因此,您似乎获得了没有属性的“ NoneType”。您的window变量没有类型,只有一个引用。

您可能需要一些依赖项-您似乎缺少定义此对象的模块。

来自Kivy Documentation

python -m pip install docutils pygments pypiwin32 kivy.deps.sdl2
kivy.deps.glew
python -m pip install kivy.deps.gstreamer

希望能解决您的问题。