I am building a PyQt5 project, that executes some database operations, and I am trying to create an executable with pyinstaller
at Windows 10.
I have created a conda environment, with the relative libraries and my folder structure is like the following:
application
|_ __init__.py
|_ main_designer.py
|_ main_designer.ui
|_ db
|_ __init__.py
|_ db_construct.py
|_ model
|_ __init__.py
|_ ecj.py (some problem-specific data-model)
main_designer.py
is importing db
and db.model
, and has the following structure:
import PyQt5.QtWidgets as qtw
from PyQt5.QtCore import QProcess
from PyQt5.uic import loadUi
import sys
import os
# sys.path.append(os.path.abspath('db')) # does not seem to help
import db
import db.model
class MainUI(qtw.QMainWindow):
def __init__(self, parent=None):
super(MainUI, self).__init__()
loadUi('main_designer.ui', self)
...
# class methods
if __name__ == "__main__":
# Create the application
app = qtw.QApplication(sys.argv)
# Create and show the application's main window
win = MainUI()
win.show()
# Run the application's main loop
sys.exit(app.exec())
I am creating an executable with pyinstaller trying among others pyinstaller -w -p .\db .\main_designer.py
(to include the db in PYTHONPATH) and pyinstaller -w -F .\main_designer.py
.
Here is main_designer.spec
:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['main_designer.py'],
pathex=['.\\db'],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
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_designer',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
console=False,
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None )
coll = COLLECT(exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
upx_exclude=[],
name='main_designer')
With every variant, when I run the executable I get the ModuleNotFound
error, when main_designer
is including the db
module, see below:
The rather strange thing is that when I execute the script from the Python command line, like python main_designer.py
, the script runs normally. Is that a virtual environment side-effect?