Search code examples
pythonimportpathpyinstallerexecutable

PyInstaller Isn't Bundling Accessory Script


I am attempting to make a .exe file of my Python script main_program.py. This script runs in a virtual environment. When I make my main_program.exe, I do so with my venv activated. My folder structure is as follows:

-Include
-Lib
-Scripts
-main_program.py
-accessory_script.py

accessory_script.py contains functions which I import in main_program.py. However, even though PyInstaller makes a mostly-functioning main_program.exe file, when I run the aformentioned executable, I get an [Errno 2]: No such file or directory: path\\to\\appdata\\local\\temp\\MEI9882\\accessory_script.pyc.

When I run pyinstaller main_program.py to generate the dist folder alone, I don't see the accessory_script.pyc in the folder. My question is, what do I need to do to ensure that accessory_script.py is incorporated into the executable of my main program?


Solution

  • I found out that the accessory script was being incorporated into my EXE correctly by Python. Most of the functions in the accessory script were being called correctly by my main program. However, one of the functions (the one that caused the FileNotFound error) had a @reloading decorator from the reloading module. This module reads the source code of a program without losing the state of the program. Because I was running my code via an EXE, there was no source code to search for. As soon as I removed this import and the associated decorators, my program worked again.