我在用着QtWebEngineWidgets
, QtWebChannel
创建 PyQt5 应用程序,它使用 HTML、CSS、JavaScript。
当我们以一般方式运行时,即运行正常,python main.py
导入 HTML 如下,
current_dir = os.path.dirname(os.path.realpath(__file__))
filename = os.path.join(current_dir, "index.html")
url = QtCore.QUrl.fromLocalFile(filename)
导入 CSS、JavaScript 文件如下,
# in index.html
<link rel="stylesheet" href="styles.css">
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="my_custom.js"></script>
现在,我正在尝试创建一个独立的.exe
文件使用pyinstaller
.
我已经尝试过从here没有成功。
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
try:
# PyInstaller creates a temp folder and stores path in _MEIPASS
base_path = sys._MEIPASS
except Exception:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
py安装程序命令:
pyinstaller --onefile --windowed main.py
我需要在生成时手动添加静态文件.exe
文件按预期工作。我想将其包含在其中.exe
文件本身。如何得到这个?