Project_Prkt
Project_Prkt

Reputation: 91

pyInstaller doesn't import module in own package path

My current project path looks like this:

TestProject\machine_learning\gui_iris_classifier

The main file, which should be packed into an .exe-file, is located there (gui.py) and also two more source files with some utility-functions I wrote (iris_gui_v1.py and irisclassifier.py)

gui.py contains imports from these two files:

from machine_learning.gui_iris_classifier.irisclassifier import IrisClassifier
from machine_learning.gui_iris_classifier.iris_gui_v1 import Ui_Dialog

and also more imports from PyQt and sys:

import sys
from PyQt5.QtWidgets import QApplication, QDialog, QMessageBox

I am using pyinstaller v3.3.1, Windows 10 64-bit and Python 3.6.5 Anaconda.

This is the command I am using for pyinstaller:

pyinstaller --onefile --hidden-import PyQt5.sip --hidden-import machine_learning.gui_iris_classifier.irisclassifier gui.py

while I am in my project path (TestProject\machine_learning\gui_iris_classifier>).

The warngui.txt contains among others these two error messages:

missing module named 'machine_learning.gui_iris_classifier' - imported by C:\Users**\PycharmProjects\TestProject\machine_learning\gui_iris_classifier\gui.py

missing module named machine_learning - imported by C:\Users**\PycharmProjects\TestProject\machine_learning\gui_iris_classifier\gui.py

If I try to execute the generated .exe-file I get this error message:

Traceback (most recent call last):

File "gui.py", line 3

from machine_learning.gui_iris_classifier.irisclassifier import IrisClassifier

ModuleNotFoundError: No module named 'machine_learning'

[5648] Failed to execute script gui

I don't understand why pyInstaller is unable to find the module even though it is in the same folder gui.py is in?

How can I fix this?

Upvotes: 3

Views: 2344

Answers (1)

S. Nick
S. Nick

Reputation: 13691

Move the module gui.py to the folderTestProject

and execute in it:

pyinstaller --onefile --noconsole gui.py

Upvotes: 1

Related Questions