在python编译的exe文件中使用QWebEngineView出现错误“网络服务崩溃,重新启动服务”

问题描述 投票:0回答:1

然后我从 python 运行,我的代码工作正常。但?然后我运行编译后的执行文件,使用cx_freeze,我得到这个错误:

ERROR:network_service_instance_impl.cc(262)] Network service crashed, restarting service.

我编写了一个简单的可重复代码。在我的主程序中,我加载本地存储的 HTML。 在示例中,我尝试了两个选项,它们都产生相同的错误。

Python代码:

import os, sys
from PySide2 import QtWidgets
from PySide2.QtWebEngineWidgets import QWebEngineView, QWebEngineSettings
from PySide2.QtCore import QUrl

app = QtWidgets.QApplication(sys.argv)
view = QWebEngineView()

file_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "html_example.html")

local_url = QUrl.fromLocalFile(file_path)
url = 'https://google.com'

view.load(local_url)
view.show()
sys.exit(app.exec_())

setup.py代码:

# setup.py
# -*- coding: utf-8 -*-
from cx_Freeze import setup, Executable


include_files   = ['icons', 'UI' ]
options = {
    'build_exe': {'include_files'              : include_files }
}

# base = "Win32GUI"
setup(
    name            = 'works',
    version         ='1.0',
    description     = 'Tools',
    executables     = [Executable(script = "QtWebEngine_example.py")],
    options=options
)

html_example.html代码:

<!DOCTYPE html>
<html>
<body>

<h2 title="I'm a header">Hello!</h2>


</body>
</html>

我什至不知道该从哪个方向寻找原因。 我使用window操作系统,python 3.8.10,PySide2-5.15.2.1

python cx-freeze pyside2 qwebengineview
1个回答
0
投票

整个互联网都没有适合我的答案。我的案例 - 使用 pytset silenium 进行品尝,chrome 浏览器显示主题错误,没有任何帮助。解决方案很有趣...打开 DEFAULT STANDARTY Chrome 浏览器窗口,现在启动您的 .py 文件,一切正常:) 我讨厌这个东西

© www.soinside.com 2019 - 2024. All rights reserved.