Building an EXE under Windows - PyInstaller

After getting to some point where I figured my small backup app was ready for a test, I wanted to build a Windows executable of some sort.
FWIW, the app (wpBG) is intended to backup my git repos by using git ‘bundles’, and it does the basic backup I expected when run from within Visual Studio Code.

Looking around, I found the PyInstaller project, as recommended by M. Driscoll in his book “Creating GUI applications with wxPython”.

After installing PyInstaller in the VSC terminal and running the build command
PyInstaller .\

When I run the executable .\dist\wpBG\wpBG.exe either directly in the directory, from a DOS Shell, PS Shell or even from the VSC terminal, I get the same error:

PS D:\pkg\python\wpBG\dist\wpBG> .\wpBG.exe
Traceback (most recent call last):
  File "", line 31, in <module>
  File "PyInstaller\loader\", line 391, in exec_module
  File "", line 16, in <module>
ModuleNotFoundError: No module named 'git'
[15532] Failed to execute script 'wpBG' due to unhandled exception!
PS D:\pkg\python\wpBG\dist\wpBG>

Some searching for issues with PyInstaller, tells me to create a wpBG.spec file, but it gets overwritten every time I run the ‘build’ step. Nor does the information I found, really help to interpret the error message into something helpful

The code to support ‘git’ comes from: from git import Repo #pip install GitPython

Perhaps Auto PY to EXE could be of some help ?


Does your default environment contain the variable PYTHONPATH, and does it point to the correct locations for your Python install?

The error says that it could find git when it encountered (likely) your import git statement in


Thank you for the link.
I did install that program, but aside from a different way of displaying the end result, the outcome is the same

Traceback (most recent call last):
  File "", line 31, in <module>
  File "PyInstaller\loader\", line 391, in exec_module
  File "", line 16, in <module>
ModuleNotFoundError: No module named 'git'

No, I do not have such an environment variable defined, though I don’t understand how it would help since the ‘git’ it complains about might be either the git.exe or the module I Installed/imported with
from git import Repo #pip install GitPython

Are you sure your code runs without error when invoking it with python (or whatever the main code/thread name) ?

Actually, it does NOT :frowning: Would that be because all of the import code is installed inside a venv?

And, in that case, how does one take that into account for PyInstaller or any other equivalent setup?

FWIW, even building inside the venv under VSCode gives the same problem, even though the ‘compile’ runs to completion successfully.

Next, I tried to select a Python interpreter without a venv and rerun the PyInstaller command from the VSCode terminal.
The command completed and I was able to run the resulting EXE also from the VSCode terminal as a test.
As far as I could tell, the backup was executed as expected, but the GUI update was very slow, intermittent and only fully completed after the backup job was finished - i.e. very poor feedback for the user.
On top of that, exiting the app, left a part of it running - or at least in memory - and I could only figure out why I could not run the executable a second time by inspecting the Task manager.
In fact, trying to run the EXE a second time gave me the misleading information that it could not load some of the tool bar graphic files.
Killing the left over EXE in task manager allowed me to run it several times, though each time I had to terminate the ‘leftover’ in the task manager.
Guess it is time to raise an issue in the PyInstaller Github forum

Just for the record:
the issue of the left-over executable task was apparently cause by the inclusion of one line at the top

class MyFrameAui(wpBgBase.MyFrameAui): 
    def __init__(self,parent):
        sys.excepthook = MyExceptionHook
        #super().__init__(None)    <<<<<<<<<<<<<<< removing this line let the app exit cleanly

as long as I only run the app and exit.
The recommended code for initialization - from the PyInstaller team - is:

 super().__init__(parent) # This is equivalent to:  wpBgBase.MyFrameAui.__init__(self,parent)

and it does fix the issue, even when I actually execute the app’s code