For your benefit I copy the relevant section here (I make the bold parts for emphasis)
--- EXTRACT FROM PYINSTALER DOCS---
Using
When your program is not bundled, the Python variable
For example, if you import mypackage.mymodule from a bundled script, then the __file__ attribute of that module will be sys._MEIPASS + 'mypackage/mymodule.pyc'. So if you have a data file at mypackage/file.dat that you added to the bundle at mypackage/file.dat, the following code will get its path (in both the non-bundled and the bundled case):
The last snippet show what/how you need to change your code (not the spc file).
--- EXTRACT FROM PYINSTALER DOCS---
Using
__file__
When your program is not bundled, the Python variable
__file__
refers to the current path of the module it is contained in. When importing a module from a bundled script, the PyInstaller bootloader will set the module’s __file__
attribute to the correct path relative to the bundle folder.For example, if you import mypackage.mymodule from a bundled script, then the __file__ attribute of that module will be sys._MEIPASS + 'mypackage/mymodule.pyc'. So if you have a data file at mypackage/file.dat that you added to the bundle at mypackage/file.dat, the following code will get its path (in both the non-bundled and the bundled case):
from os import path path_to_dat = path.join(path.dirname(__file__), 'file.dat')In the bundled main script itself the above might not work, as it is unclear where it resides in the package hierarchy. So in when trying to find data files relative to the main script, sys._MEIPASS can be used. The following will get the path to a file other-file.dat next to the main script if not bundled and in the bundle folder if it is bundled:
from os import path import sys bundle_dir = getattr(sys, '_MEIPASS', path.abspath(path.dirname(__file__))) path_to_dat = path.join(bundle_dir, 'other-file.dat')---- END OF EXTRACT ---
The last snippet show what/how you need to change your code (not the spc file).
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs