I am using pyinstaller to create EXE from a script. The location of script and exe are as follows:
Script: root-dir\subdir1\subdir2\src\scriptabc.py
Exe: root-dir\subdir1\subdir2\exe\scriptabc.exe
To create Exe I run cmd commands from Exe directory.
pyinstaller -F -i ABC.ico "..\src\scriptabc.py"
The resulting files are correctly created in Exe folder with the executable in dist folder. I then copy the executable in Exe folder, such that it is at the same depth level as src\scriptabc.py file with reference to root.
When I run the exe, all code items where I used relative paths, such as
wb_assets = load_workbook(filename = '..//input//01_assets.xlsx')
run just fine.
However, when the code comes to absolute path evaluation using pathlib, it fails with the following error:
File "pathlib.py", line 587, in __getitem__
IndexError: 3
[8920] Failed to execute script scriptabc
I am using pathlib to establish absolute path of the root-dir as follows:
from pathlib import Path
abspath = Path(__file__).resolve() # resolve to relative path to absolute
rootpath = abspath.parents[3] # root-dir
There is a lot of code which then creates paths for other sub directories once I establish rootpath.
So this index number works fine when working with src*.py folder Why does it then give an error for an exe sitting in exe*.exe folder?
Is the file option only looking at the script filename? Because if it is the depth, the exe and src folders are exactly same depth.
The exe works just fine if I copy paste in src folder and run from there. In my exe distribution, I just don't want to have src folder at all, just let the code run from exe folder if possible.
Can someone please help with that?
The second part of the question is that I am looking for spec script which thoroughly includes all dll files (I want them bundled in the exe instead of getting redist package installed on every computer. I have the SDK and all required dll files in my computer). Do I need to ask another question for it?