I'm using QtWebEngineWidgets
, QtWebChannel
to create PyQt5 application, which uses HTML, CSS, JavaScript.
It's working fine, when we run in general way i.e., python main.py
Importing HTML as below,
current_dir = os.path.dirname(os.path.realpath(__file__))
filename = os.path.join(current_dir, "index.html")
url = QtCore.QUrl.fromLocalFile(filename)
Importing CSS, JavaScript files as below,
# 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>
Now, I'm trying to create a standalone .exe
file using pyinstaller
.
I have tried from here with no success.
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)
Pyinstaller command:
pyinstaller --onefile --windowed main.py
I need to manually add static files at generated .exe
file to work as expected. Which I want to include it in .exe
file itself. How to get this?