解決AttributeError:'NoneTypeobject'?has?no?attribute'Window'的問(wèn)題(親測(cè)有效)
已解決VSCode運(yùn)行強(qiáng)化學(xué)習(xí)代碼拋出異常AttributeError: ‘NoneType’ object has no attribute ‘Window’
pyglet.canvas.xlib.NoSuchDisplayException: Cannot connect to “None” 的正確解決方法,親測(cè)有效??!
報(bào)錯(cuò)問(wèn)題
一個(gè)小伙伴遇到問(wèn)題跑來(lái)私信我,在VSCode運(yùn)行強(qiáng)化學(xué)習(xí)代碼,但是發(fā)生了報(bào)錯(cuò)(當(dāng)時(shí)他心里瞬間涼了一大截,跑來(lái)找我求助,然后順利幫助他解決了,順便記錄一下希望可以幫助到更多遇到這個(gè)bug不會(huì)解決的小伙伴),報(bào)錯(cuò)代碼如下所示:
import pyglet window = pyglet.window.Window(500, 500)
報(bào)錯(cuò)信息內(nèi)容如下所示:
Traceback (most recent call last): File "/home/justin/.local/lib/python3.8/site-packages/pyglet/__init__.py", line 334, in __getattr__ return getattr(self._module, name) AttributeError: 'NoneType' object has no attribute 'Window' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "/home/justin/Dropbox/jr/py/pyglet_games/pyglet_demo/displaytest.py", line 5, in <module> window = pyglet.window.Window(500, 500) File "/home/justin/.local/lib/python3.8/site-packages/pyglet/__init__.py", line 340, in __getattr__ __import__(import_name) File "/home/justin/.local/lib/python3.8/site-packages/pyglet/window/__init__.py", line 1891, in <module> gl._create_shadow_window() File "/home/justin/.local/lib/python3.8/site-packages/pyglet/gl/__init__.py", line 220, in _create_shadow_window _shadow_window = Window(width=1, height=1, visible=False) File "/home/justin/.local/lib/python3.8/site-packages/pyglet/window/xlib/__init__.py", line 171, in __init__ super(XlibWindow, self).__init__(*args, **kwargs) File "/home/justin/.local/lib/python3.8/site-packages/pyglet/window/__init__.py", line 573, in __init__ display = pyglet.canvas.get_display() File "/home/justin/.local/lib/python3.8/site-packages/pyglet/canvas/__init__.py", line 94, in get_display return Display() File "/home/justin/.local/lib/python3.8/site-packages/pyglet/canvas/xlib.py", line 123, in __init__ raise NoSuchDisplayException('Cannot connect to "%s"' % name) pyglet.canvas.xlib.NoSuchDisplayException: Cannot connect to "None"
報(bào)錯(cuò)翻譯
報(bào)錯(cuò)信息內(nèi)容翻譯如下所示:
屬性錯(cuò)誤:“NoneType”對(duì)象沒(méi)有屬性“Window”
pyglet.canvas.xlib.NoSuch顯示異常:無(wú)法連接到“None”
報(bào)錯(cuò)原因
報(bào)錯(cuò)原因:
在其他少數(shù)情況下,它不是以一種方式運(yùn)行而不是以另一種方式工作的。大多數(shù)解決方案都涉及更改圖形卡設(shè)置或運(yùn)行X11服務(wù)器。這在這里似乎不相關(guān),因?yàn)樗坪踔慌cVSCode相關(guān)。
小伙伴們按照下面的方法配置vscode即可即可?。?!
解決方法
這是vscode內(nèi)部終端的問(wèn)題,將控制臺(tái)設(shè)置為launch.json中的另一個(gè)選項(xiàng)解決了這個(gè)問(wèn)題:
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [ { "name": "Python: Current File", "type": "python", "request": "launch", "program": "${file}", "console": "externalTerminal" } ] }
因此,事實(shí)上,在python腳本中添加以下內(nèi)容可以解決問(wèn)題(至少結(jié)合切換到Wayland):
import os os.environ['DISPLAY'] = ':1'
以上是此問(wèn)題報(bào)錯(cuò)原因的解決方法,歡迎評(píng)論區(qū)留言討論是否能解決,如果有用歡迎點(diǎn)贊收藏文章謝謝支持,博主才有動(dòng)力持續(xù)記錄遇到的問(wèn)題?。?!
到此這篇關(guān)于解決AttributeError: ‘NoneType‘ object has no attribute ‘Window‘的問(wèn)題(親測(cè)有效)的文章就介紹到這了,更多相關(guān)NoneType object has no attribute 內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
- python錯(cuò)誤:AttributeError: ''module'' object has no attribute ''setdefaultencoding''問(wèn)題的解決方法
- 解決python多線程報(bào)錯(cuò):AttributeError: Can''t pickle local object問(wèn)題
- Python3下錯(cuò)誤AttributeError: ‘dict’ object has no attribute’iteritems‘的分析與解決
- Python 中 AttributeError: ‘NoneType‘ object has no attribute ‘X‘ 錯(cuò)誤問(wèn)題解決方案
- Python進(jìn)程崩潰AttributeError異常問(wèn)題解決
- Pytorch出現(xiàn)錯(cuò)誤Attribute?Error:module?‘torch‘?has?no?attribute?'_six'解決
相關(guān)文章
Python內(nèi)置模塊Collections的使用教程詳解
collections 是 Python 的一個(gè)內(nèi)置模塊,所謂內(nèi)置模塊的意思是指 Python 內(nèi)部封裝好的模塊,無(wú)需安裝即可直接使用。本文將詳解介紹Collections的使用方式,需要的可以參考一下2022-03-03Python操作MySQL數(shù)據(jù)庫(kù)9個(gè)實(shí)用實(shí)例
這篇文章主要介紹了Python操作MySQL數(shù)據(jù)庫(kù)9個(gè)實(shí)用實(shí)例,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2015-12-12python numpy實(shí)現(xiàn)文件存取的示例代碼
這篇文章主要介紹了python numpy實(shí)現(xiàn)文件存取的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-05-05Python Pandas 轉(zhuǎn)換unix時(shí)間戳方式
今天小編就為大家分享一篇Python Pandas 轉(zhuǎn)換unix時(shí)間戳方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-12-12python使用pooch實(shí)現(xiàn)下載網(wǎng)絡(luò)文件
pooch是python的一個(gè)模塊,主打一個(gè)更加方便地下載文件,適用于科研人員和開(kāi)發(fā)者,目前,已經(jīng)有scikit-image, MetPy, scipy, seaborn等項(xiàng)目采用pooch作為內(nèi)置數(shù)據(jù)集的下載方法,本文給大家介紹了python用pooch便捷地下載網(wǎng)絡(luò)文件,需要的朋友可以參考下2024-01-01Python中l(wèi)ogging日志模塊代碼調(diào)試過(guò)程詳解
這篇文章主要介紹了Python中l(wèi)ogging日志模塊代碼調(diào)試,今天來(lái)看看如何在代碼中定義日志,并探討日志的權(quán)限,需要的朋友可以參考下2023-04-04Python函數(shù)基礎(chǔ)實(shí)例詳解【函數(shù)嵌套,命名空間,函數(shù)對(duì)象,閉包函數(shù)等】
這篇文章主要介紹了Python函數(shù)基礎(chǔ),結(jié)合實(shí)例形式詳細(xì)分析了函數(shù)嵌套,命名空間,函數(shù)對(duì)象,閉包函數(shù)等相關(guān)概念、原理、用法及操作注意事項(xiàng),需要的朋友可以參考下2019-03-03Python3字符串的常用操作方法之修改方法與大小寫(xiě)字母轉(zhuǎn)化
這篇文章主要介紹了Python3字符串的常用操作方法之修改方法與大小寫(xiě)字母轉(zhuǎn)化,文章圍繞主題展開(kāi)詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,需要的小伙伴可以參考一下2022-09-09