Situation: My Python script has a line of code that copies itself to another directory
shutil.copyfile(os.path.abspath(__file__), newPath)
Problem: The script is then compiled into an EXE and ran. The error given is as follows:
FileNotFoundError: No such file or Directory: "C:\Path\To\EXE\script.py"
As you can see, the EXE is looking for the .py
version of itself (i.e. uncompiled version)
Question: Is there another Python command that can still let the executable find itself and not the .py
version of itself?
Additional information: I was going to try to just replace .py
with .exe
and see if it works -- it would have if not for the program to fail if I change the name of the executable.
C:\ > script.exe
#Works as expected
C:\ > ren script.exe program.exe
C:\ > program.exe
FileNotFoundError: No such file or directory: "C:\script.py"