__file__ is not defined when running through pyexec
apple1417 opened this issue · comments
apple1417 commented
Basically all in the title. Demo program:
import unrealsdk
unrealsdk.Log(__file__)
>>> pyexec test.py <<<
NameError: name '__file__' is not defined
At:
D:\SteamLibrary\steamapps\common\Borderlands 2\Binaries\Win32\Mods\\test.py(3): <module>
>>> py from Mods import test <<<
'D:\\SteamLibrary\\steamapps\\common\\Borderlands 2\\Binaries\\Win32\\Mods\\test.py'
Workaround: cause an exception and extract the file path from it. Put this code near the top of the file:
if __name__ == "__main__":
import sys
try:
raise NotImplementedError
except NotImplementedError:
__file__ = sys.exc_info()[-1].tb_frame.f_code.co_filename # type: ignore
apple1417 commented
Fixed in pybind 2.8, if we upgrade.
apple1417 commented
Fixed, but leaving open for documentation until released.