Python 无法获取窗口,中止

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40697876/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 23:51:21  来源:igfitidea点击:

Unable to get a window, abort

pythonkivy

提问by foosion

I'm getting what seems to be a common error running the Kivy hello world program. I've tried the solutions I've seen here: manually install gstreamer, adding it to PATHand installing PySDL2. My OS is Windows 7, all other version info is in the error log.

我在运行 Kivy hello world 程序时遇到了似乎是一个常见错误。我已经尝试了我在这里看到的解决方案:手动安装gstreamer,将其添加到PATH并安装PySDL2. 我的操作系统是 Windows 7,所有其他版本信息都在错误日志中。

# you need this two lines:
import os
os.environ['KIVY_IMAGE'] = 'pil,sdl2'

#kivy program
from kivy.app import App
from kivy.uix.button import Button

class TestApp(App):
    def build(self):
        return Button(text='Hello World')

TestApp().run()

The error log:

错误日志:

[INFO              ] [Logger      ] Record log in C:\Users\xyz\.kivy\logs\kivy_16-11-19_11.txt
[INFO              ] [Kivy        ] v1.9.1
[INFO              ] [Python      ] v2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:24:40) [MSC v.1500 64 bit (AMD64)]
[INFO              ] [Factory     ] 179 symbols loaded
[INFO              ] [Image       ] Providers: img_pil, img_sdl2 (img_tex, img_dds, img_ffpyplayer, img_gif ignored)
[INFO              ] [Text        ] Provider: sdl2
[INFO              ] [OSC         ] using <thread> for socket
[INFO              ] [Window      ] Provider: sdl2
[INFO              ] [GL          ] GLEW initialization succeeded
[INFO              ] [GL          ] OpenGL version <3.1.0 - Build 8.15.10.2538>
[INFO              ] [GL          ] OpenGL vendor <Intel>
[INFO              ] [GL          ] OpenGL renderer <Intel(R) HD Graphics Family>
[INFO              ] [GL          ] OpenGL parsed version: 3, 1
[INFO              ] [GL          ] Shading version <1.40  - Intel Build 8.15.10.2538>
[INFO              ] [GL          ] Texture max size <8192>
[INFO              ] [GL          ] Texture max units <16>
[INFO              ] [Shader      ] fragment shader: <No errors.>
[INFO              ] [Shader      ] vertex shader: <No errors.>
[INFO              ] [Shader      ] program: <No errors.>
[CRITICAL          ] [Window      ] Unable to find any valuable Window provider at all!
sdl2 - AttributeError: tobytes
  File "C:\Program Files\python27\lib\site-packages\kivy\core\__init__.py", line 67, in core_select_lib
    cls = cls()
  File "C:\Program Files\python27\lib\site-packages\kivy\core\window\window_sdl2.py", line 138, in __init__
    super(WindowSDL, self).__init__()
  File "C:\Program Files\python27\lib\site-packages\kivy\core\window\__init__.py", line 722, in __init__
    self.create_window()
  File "C:\Program Files\python27\lib\site-packages\kivy\core\window\window_sdl2.py", line 255, in create_window
    super(WindowSDL, self).create_window()
  File "C:\Program Files\python27\lib\site-packages\kivy\core\window\__init__.py", line 897, in create_window
    self.render_context = RenderContext()
  File "kivy\graphics\instructions.pyx", line 756, in kivy.graphics.instructions.RenderContext.__init__ (kivy\graphics\instructions.c:10729)
  File "C:\Program Files\python27\lib\site-packages\kivy\core\image\__init__.py", line 512, in __init__
    self.filename = arg
  File "C:\Program Files\python27\lib\site-packages\kivy\core\image\__init__.py", line 700, in _set_filename
    mipmap=self._mipmap, nocache=self._nocache)
  File "C:\Program Files\python27\lib\site-packages\kivy\core\image\__init__.py", line 430, in load
    im = loader(filename, **kwargs)
  File "C:\Program Files\python27\lib\site-packages\kivy\core\image\__init__.py", line 198, in __init__
    self._data = self.load(filename)
  File "C:\Program Files\python27\lib\site-packages\kivy\core\image\img_pil.py", line 101, in load
    return list(self._img_read(im))
  File "C:\Program Files\python27\lib\site-packages\kivy\core\image\img_pil.py", line 86, in _img_read
    img_tmp.mode.lower(), img_tmp.tobytes())
  File "C:\Program Files\python27\lib\site-packages\PIL\Image.py", line 514, in __getattr__
    raise AttributeError(name)

[CRITICAL          ] [App         ] Unable to get a Window, abort.
 Exception SystemExit: 1 in 'kivy.properties.dpi2px' ignored
[CRITICAL          ] [App         ] Unable to get a Window, abort.

回答by Suraj Kumar

In cmd go to python34 and then to Scripts and install the following:

在 cmd 中转到 python34,然后转到 Scripts 并安装以下内容:

pip install --upgrade pip wheel setuptools
pip install docutils pygments pypiwin32 kivy.deps.sdl2 kivy.deps.glew
pip install kivy.deps.gstreamer
pip install kivy.deps.angle
pip install kivy

回答by KeyWeeUsr

Try putting <python dir>\share\sdl2\binto your path, it should do the trick. The thing is that it can't find the sdl2 binary it works with. There probably even isn't any PIL windowprovider, so using environment variable won't do a thing for creating a window (it'll be used as an image provider though).

尝试<python dir>\share\sdl2\bin使用您的路径,它应该可以解决问题。问题是它找不到它使用的 sdl2 二进制文件。甚至可能没有任何 PIL windowprovider,因此使用环境变量不会为创建窗口做任何事情(尽管它将用作图像提供程序)。

I'm not really familiar with PySDL2, so I can't help you with that, however I made an installerfor Kivy on Windows to make things easier for beginners.

我对 PySDL2 不是很熟悉,所以我无法帮助你,但是我为 Windows 上的 Kivy制作了一个安装程序,让初学者更容易。

There are basically two ways you'll end up with anyway:

无论如何,您最终会以两种方式结束:

  1. You'll put the binfolders to a PATHvariable permanently

    I consider it really stupid unless you're sure you won't delete Python or the folder, otherwise you'll have a ghost folder in PATH+ all other programs will have an access to files in binfolders via PATH

  2. You'll have a batch file that does that temporarily

    Only programs ran from the console/batch will have an access to the binfolder.

  1. 你将把bin文件夹PATH永久地放到一个变量中

    我认为这真的很愚蠢,除非你确定你不会删除 Python 或文件夹,否则你会有一个幽灵文件夹PATH+ 所有其他程序都可以通过以下方式访问文件bin夹中的文件PATH

  2. 您将有一个临时执行此操作的批处理文件

    只有从控制台/批处理运行的程序才能访问该bin文件夹。

The installer does that for you and in fact does even installing from scratch (no Python) or many other things.

安装程序会为您完成这项工作,实际上甚至可以从头开始安装(没有 Python)或许多其他东西。

In case you haven't installed the Kivy dependencies, please do it first.

如果您还没有安装 Kivy依赖项,请先安装。

回答by Robert Holmes

Not sure about Windows or Linux, but on python-for-android at the very top you need to put:

不确定 Windows 或 Linux,但在最顶部的 python-for-android 上,您需要放置:

#qpy:kivy
import kivy
kivy.require('1.10.1') # replace with your current kivy version !

回答by Mahmoud Harb

Disable the 3D acceleration and the 2D video acceleration in the display settings of the virtual software (aka vmbox, vmware). I think this will work for you , it works for me after lots of tries.

在虚拟软件(又名 vmbox、vmware)的显示设置中禁用 3D 加速和 2D 视频加速。我认为这对你有用,经过多次尝试后对我有用。

回答by Ronald Saunfe

I just found a quick fix

我刚刚找到了一个快速修复

  1. Once you have installed Kivy using pip
  2. navigate to C:\Users\(accountname)\.kivy\and open the config.inifile
  3. change the multisamples = 0from = 2then restart your computer. This will save other issues too like
  1. 使用安装 Kivy 后 pip
  2. 导航到C:\Users\(accountname)\.kivy\并打开config.ini文件
  3. 更改multisamples = 0= 2然后重新启动计算机。这也将节省其他问题

[CRITICAL] [GL ] Minimum required OpenGL version (2.0) NOT found!

[关键] [GL] 未找到所需的最低 OpenGL 版本 (2.0)!

This worked for me on windows 7 64 bit, python3.5(32 bit) with Kivy version 1.10.0

这在 Windows 7 64 位,python3.5(32 位)和 Kivy版本 1.10.0上对我有用

回答by Carson Zhang

I'm using windows 10 and python 3.6, and I installed kivy using pip. None of above solution helped, but then I uninstall the kivy with pip, and install kivy again with conda according to https://kivy.org/doc/stable/installation/installation-windows.html#installationand it worked.

我使用的是 windows 10 和 python 3.6,我使用 pip 安装了 kivy。以上解决方案都没有帮助,但后来我用 pip 卸载了 kivy,然后根据https://kivy.org/doc/stable/installation/installation-windows.html#installation用 conda 再次安装了 kivy并且它起作用了。

The packages conda installed for me are: The following packages will be downloaded:

为我安装的包 conda 是: 将下载以下包:

package                    |            build
---------------------------|-----------------
freetype-2.8.1             |           vc14_0         469 KB  conda-forge
sdl2_mixer-2.0.4           |       h6538335_0          83 KB  conda-forge
sdl2-2.0.10                |       h6538335_0         4.3 MB  conda-forge
kivy-1.11.1                |   py36hbc14df2_0        20.2 MB  conda-forge
sdl2_image-2.0.2           |                0         293 KB  conda-forge
glew-2.0.0                 |    he025d50_1002         722 KB  conda-forge
sdl2_ttf-2.0.14            |       h8909db8_1          25 KB  conda-forge
smpeg2-2.0.0               |       h6538335_1         131 KB  conda-forge
------------------------------------------------------------

回答by Joel Imbergamo

I've uninstalled Python directly and reintalled all and it worked for me, i know it's not the best but at least works.

我已经直接卸载了 Python 并重新安装了所有,它对我有用,我知道它不是最好的,但至少有效。