I have a .py script which import some functions from an another .py script, located in an another directory in the same folder. And some of those scripts import functions from some other .py scripts contained in the folder itself.
I have created an executable file of my main.py
file (which eventually uses functions from all other files) using pyinstaller. However when executed, the .exe application, located in the
./dist
folder just opens up and closes immediately.
I tried to find the error by executing the file through cmd /K
in Command Prompt, which lets the file to remain open even after executing and show errors. This is what I got :
As you can see it showed this error :
FileNotFoundError: [Errno 2] No such file or directory: './Static/user.txt'
FYI: This is a block of code which reads some text from the given .txt file (works fine when run through VsCode terminal), but here it fails to detect the path / locate it, Why?
The tree of my cwd is like this (below). The user.txt
file is located inside the ./Static
(at bottom) and the .py script reads some text from it, which it isn’t able to do now for some reason, while executed in an .exe
format.
Any kind of help or suggestions would be really helpful, Thanks!
Advertisement
Answer
Are you using the current working directory (cwd) to define the relative path of the text file ?
If yes , remove the exe from the dist folder or put ./Static inside the dist folder.