0

When I run

print(__file__)

in Spyder, the absolute location is returned (e.g. C:\Users\test\test.py).

However, when I run the same code after I compiled it into an exe via pyinstaller, only the name of the py file is printed (just test.py).

How can I fix this?

1 Answers1

1

In an exe __file__ is not accurate, see this previous answer.

In short:

import sys
if getattr(sys, 'frozen', False):
    # Pyinstaller exe
    location = sys.executable
else:
    # Running directly python
    location = __file__
Cirrith
  • 82
  • 8