[pyqtdeploy] ModuleNotFoundError after compilation

Kristófer Reykjalín Þorláksson kristofer at thorlaksson.com
Sat Jun 27 13:48:34 BST 2020


I have a project with the following folder structure:

    project/
        __init__.py
        main.py
        ui/
            __init__.py
            mainwindow.py
            otherfile.py

The main.py file has the following import statement:

    from ui.mainwindow import MainWindow

When I run the project using `python main.py` it runs fine, but after
compiling via `pyqtdeploy` I get the following error when I run the
executable:

    ModuleNotFoundError: No module named 'ui'

After reading through one of the other threads on the mailing list [0] I
realized that I was able to successfully build and run the project by
changing the `mainwindow` import statement to:

    from project.ui.mainwindow import MainWindow

However, after making that change running `python main.py` no longer
works, because the path `project.ui.mainwindow` doesn't exist.

[0]:
http://python.6.x6.nabble.com/pyqtdeploy-build-can-t-find-modules-td5185029.html

I also tried a suggestion in the aforementioned thread and moved
`main.py` to be at the same level as `project` like so:

    __init__.py
    main.py
    project/
        __init__.py
        ui/
            __init__.py
            mainwindow.py
            otherfile.py

But that didn't work either; I could run the project using `python
main.py`, but got the same ModuleNotFoundError after buidling via
pyqtdeploy.


This isn't much more than an annoyance, but being forced to change the
import path before building the project is a _bit frustrating_.
Is it possible to have one import statement that works for both running
the project via `python main.py` and running the built executable that
does not including messing with path settings?


Best regards,
Kristófer R.


More information about the PyQt mailing list