2

How do I make a executable compiled with pyinstaller find its own name? I need this to make it copy itself to startup. Or is there another way to achieve this?

file only finds the original name of the script, not the executable.

Jorrit Wegman
  • 93
  • 1
  • 7

1 Answers1

1

Hope this solves your problem

import os
import sys

# uncompiled file.py can be found by
file_name = os.path.basename(__file__)

# compiled file.exe can find itself by
file_name = os.path.basename(sys.executable)

# and path to py or exe

current_path = os.path.realpath(sys.executable)
current_path = os.path.realpath(__file__)
JJJ
  • 32,902
  • 20
  • 89
  • 102
Test
  • 39
  • 6