I'm trying to package a PySide2 test application with the following structure:
.
├── main.py
├── main.spec
└── wizardUI
├── 10.toolBoxBtns.ui
├── 11.toolBoxShrCt.ui
├── 12.propertyBox.ui
├── 13.printing.ui
├── 14.settings.ui
├── 15.coclusion.ui
├── 1.welcomePage.ui
├── 2.graphicsScene.ui
├── 3.graphicsSceneText.ui
├── 4.textDialog.ui
├── 5.codeDialog.ui
├── 6.graphicsSceneBox.ui
├── 7.graphicsScenePixmap.ui
├── 8.graphicsSceneShrCt.ui
├── 9.toolbox.ui
└── wizard.py
When I try to run an executable I get this error:
FileNotFoundError: No such file or directory:'/home/artem/Desktop/testUI/dist/main/wizardUI'
Here's my wizard.py file
from PySide2 import QtCore, QtWidgets
from PySide2.QtUiTools import QUiLoader
import os
class tutorWizard(QtWidgets.QWizard):
""" Contains introduction tutorial """
def __init__(self, parent=None):
super(tutorWizard, self).__init__(parent)
self.setWindowTitle("Introduction tutorial")
pages = self.findPages()
self.initPages(pages)
def findPages(self):
ui_files = []
cnt = 1
current_dir = os.path.dirname(os.path.realpath(__file__))
while len(ui_files) != 15:
for file in os.listdir(current_dir):
if file.startswith("{}.".format(cnt)):
ui_files.append(os.path.join(current_dir, file))
cnt += 1
return ui_files
def initPages(self, files):
loader = QUiLoader()
for i in files:
file = QtCore.QFile(str(i))
file.open(QtCore.QFile.ReadOnly)
file.reset()
page = loader.load(file)
file.close()
self.addPage(page)
main.py is:
from PySide2.QtWidgets import QApplication
from wizardUI.wizard import tutorWizard
import sys
app = QApplication(sys.argv)
window = tutorWizard()
window.show()
sys.exit(app.exec_())
and .spec file is:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['main.py'],
pathex=['/home/artem/Desktop/testUI'],
binaries=[],
datas=[],
hiddenimports=['PySide2.QtXml'],
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,
[],
exclude_binaries=True,
name='main',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=True )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='main')
a.datas += Tree('/home/artem/Desktop/testUI/wizardUI')
Is there any way to solve this error without changig current_dir
variable in wizard.py ?