I think you need to special-case when it's frozen:

# determine if application is a script file or frozen exeif
getattr(sys, 'frozen', False):
    application_path = os.path.dirname(sys.executable)elif __file__:
    application_path = os.path.dirname(__file__)

from:

https://stackoverflow.com/questions/404744/determining-application-path-in-a-python-exe-generated-by-pyinstaller

On Wed, Jun 4, 2025 at 1:17 PM Judd Gledhill <[email protected]>
wrote:

> Hello,
>
> I am converting some small scripts to exe files to host on a Citrix
> server. I am hoping to be able to get the path to the .exe file so I can
> traverse to folders next to the exe file itself. Right now I use:
>
> script_path = os.path.abspath(__file__) #path to this script
>
> But this fails at runtime with the exe file. I read the notes about
> __file__ but do not want to bundle the files into the exe itself. How can I
> find the path to the exe that is running?
>
> Thanks,
>
> Judd
>
> --
> You received this message because you are subscribed to the Google Groups
> "PyInstaller" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion visit
> https://groups.google.com/d/msgid/pyinstaller/84bc6f62-3d54-4aef-b6ee-ca8f667f2113n%40googlegroups.com
> <https://groups.google.com/d/msgid/pyinstaller/84bc6f62-3d54-4aef-b6ee-ca8f667f2113n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>


-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

[email protected]

-- 
You received this message because you are subscribed to the Google Groups 
"PyInstaller" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion visit 
https://groups.google.com/d/msgid/pyinstaller/CALGmxEJJNoNC%2BtgoS6Vk8nKNwK0BgvwYhmPkKXGhnnp6pZGqdw%40mail.gmail.com.

Reply via email to