'after converting python file to one file exe when i run it [FileNotFoundError]

How to access the file:

import os
os.chdir(os.path.dirname(os.path.abspath(__file__)))

def main():
    with open("pass.txt", "r") as pf:  ## This is line 51 in the screenshot
        passwds = pf.read().splitlines()
    
    # some codes

if __name__ == "__main__":
    main()  ## This is line 83 in the screenshot

I used this

pyinstaller --clean --onefile start.py

Screenshot: Note that the files are located next to the executable file

Traceback (most recent call last):
  File "start.py", line 83, in <module>
  File "start.py", line 51, in main
FileNotFoundError: [Errno 2] No such file or directory: 'pass.txt'
[50416] Failed to execute script 'start' due to unhandled exception!

When i used:

pyinstaller start.py

That is, it is not in one file, it was working without problems, but there are many files next to it, and I do not want this

But when I use make it to one file --onefile the problem occurs

How can this problem be solved?



Solution 1:[1]

The solution is here

thanks for your efforts I really appreciate you martineau <3

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mr.Neo