Python pywebview webview.start

分享于2022年07月17日 python pywebview webview 问答
【问题标题】:Python pywebview webview.start() System.NullReferenceException 对象引用未在 System.Windows.Forms.Control.get_CacheTextInternal() 处设置(Python pywebview webview.start() System.NullReferenceException object reference not set at System.Windows.Forms.Control.get_CacheTextInternal())
【发布时间】:2022-07-13 17:38:43
【问题描述】:

我按照 https://pypi.org/project/pywebview/ 所示的方式进行了安装,并且我使用了示例代码

import webview
webview.create_window('Hello world', 'https://pywebview.flowrl.com/hello')
webview.start()

这是我得到的完整错误

Unbehandelte Ausnahme: System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
   bei System.Windows.Forms.Control.get_CacheTextInternal()
   bei System.Windows.Forms.Control.get_Text()
   bei System.Windows.Forms.Control.set_Text(String value)
--- Ende der Stapel�berwachung vom vorhergehenden Ort, an dem die Ausnahme ausgel�st wurde ---
   bei System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   bei Python.Runtime.PythonException.ThrowLastAsClrException()
   bei Python.Runtime.Dispatcher.TrueDispatch(Object[] args)
   bei Python.Runtime.Dispatcher.Dispatch(Object[] args)
   bei __System_Threading_ThreadStartDispatcher.Invoke()
   bei System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
   bei System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   bei System.Threading.ThreadHelper.ThreadStart()

我尝试调试 webview.start()。尽管 windows[0] 不是空的,但它在 guilib.create_window(windows[0]) 处崩溃


【解决方案1】:

遇到了同样的问题,可以通过将 pythonnet 的版本降低到“3.0.0a2”来解决它。之后的一切(截至目前/13.07.2022)都不再起作用了。以下是诀窍:

pip install pythonnet==3.0.0a2
pip install pywebview==3.6.3