I want to convert my .py that load with the UI file into exe.
I had followed the steps from PyInstaller + Ui Files and PyInstaller + UI Files - FileNotFoundError: [Errno 2] No such file or directory:
I added the resource_path method code in my .py
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)
form = resource_path("qt_designer.ui")
Ui_MainWindow, QtBaseClass = uic.loadUiType(form)
I had also made changes to my MyApplication.spec as such:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['main.py'],
pathex=['C:\\Users\\Alvin\\PycharmProjects\\untitled'],
binaries=[],
datas=[('C:\\Users\\Alvin\\PycharmProjects\\untitled\\qt_designer.ui',".")],
hiddenimports=[],
hookspath=[],
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
cipher=block_cipher)
exe = EXE(pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='MyApplication',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True )
But I am getting this error :
Traceback (most recent call last):
File "main.py", line 380, in <module>
File "main.py", line 36, in __init__
File "site-packages\PyQt5\uic\__init__.py", line 227, in loadUi
File "site-packages\PyQt5\uic\Loader\loader.py", line 72, in loadUi
File "site-packages\PyQt5\uic\uiparser.py", line 1013, in parse
File "xml\etree\ElementTree.py", line 1196, in parse
File "xml\etree\ElementTree.py", line 586, in parse
FileNotFoundError: [Errno 2] No such file or directory: 'qt_designer.ui'
[761476] Failed to execute script main
Screenshot of the error
Can anyone help me to point out my mistake or steps that I followed wrongly?