欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

pcCharm配置环境不当导致出错python+kivy:raiseExceptionUnabletogetaWindow

时间:2023-05-15

python+kivy小程序出错,代码如下:

import osos.environ['KIVY_IMAGE'] = 'pil,sdl2'from kivy.app import Appfrom kivy.uix.floatlayout import FloatLayoutclass SizeFloat(FloatLayout): def __init__(self, **kwargs): super().__init__(**kwargs)class SizeApp(App): def build(self): return SizeFloat()if __name__ == '__main__': SizeApp().run()

运行后出错信息如下:

[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 causessdl2 - Exception: SDL2: Unable to load image File "D:vs2017SharedPython37_86libsite-packageskivycore__init__.py", line 70, in core_select_lib cls = cls() File "D:vs2017SharedPython37_86libsite-packageskivycorewindowwindow_sdl2.py", line 152, in __init__ super(WindowSDL, self).__init__() File "D:vs2017SharedPython37_86libsite-packageskivycorewindow__init__.py", line 982, in __init__ self.create_window() File "D:vs2017SharedPython37_86libsite-packageskivycorewindowwindow_sdl2.py", line 311, in create_window super(WindowSDL, self).create_window() File "D:vs2017SharedPython37_86libsite-packageskivycorewindow__init__.py", line 1268, in create_window self.render_context = RenderContext() File "kivygraphicsinstructions.pyx", line 783, in kivy.graphics.instructions.RenderContext.__init__ File "D:vs2017SharedPython37_86libsite-packageskivycoreimage__init__.py", line 561, in __init__ self.filename = arg File "D:vs2017SharedPython37_86libsite-packageskivycoreimage__init__.py", line 756, in _set_filename mipmap=self._mipmap, nocache=self._nocache) File "D:vs2017SharedPython37_86libsite-packageskivycoreimage__init__.py", line 460, in load im = loader(filename, **kwargs) File "D:vs2017SharedPython37_86libsite-packageskivycoreimage__init__.py", line 223, in __init__ self._data = self.load(filename) File "D:vs2017SharedPython37_86libsite-packageskivycoreimageimg_sdl2.py", line 47, in load raise Exception('SDL2: Unable to load image')[CRITICAL] [App ] Unable to get a Window, abort.Process finished with exit code 1

经查阅大家解决方案,发现是pcCharm的环境未配置正确,解决方案如下:

在pcCharm中按下“ctrl+alt+s”,调出如下Settings界面:

找到Project:xxxx(xxxx为当前的项目名称)

并点击“Python Interpreter”

 

单击“Python Interpreter”,显示“Python Interpreter:框”在右侧有一个“齿轮”按钮,单击,如图所示:

 单击“齿轮”,显示出“add...”,“Show all”,单击“add...”,如下所示:

单击"virtualenv environment”,右侧中选择"existing environment",勾选"make available to all projects”,并单击最右侧“...”图标,如下所示:

弹出“select python interpreter”中,选中“*****kv-demon-envscriptspython.exe”,单击“OK”,如下所示:

 返回界面,确认interpreter右侧的路径框中,已经变更为“*****kv-demon-envscriptspython.exe”,再单击ok,如下所示:

回到上一界面,pcCharm会自动更新安装对应的包,稍等一会儿,会形成一下清单,可以看到,python interpreter右侧的框是“*****kv-demon-envscriptspython.exe”,下面列出了package清单,现有的版本,最新的版本,如下所示,再单击“ok"

再运行程序代码,成功解决!

 

 

 

 

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。