diff --git a/src/App/FreeCADInit.py b/src/App/FreeCADInit.py index 52ae425b45..471f435dc4 100644 --- a/src/App/FreeCADInit.py +++ b/src/App/FreeCADInit.py @@ -1204,7 +1204,7 @@ class DirMod(Mod): try: source = init_py.read_text(encoding="utf-8") code = compile(source, init_py, 'exec') - exec(code) + exec(code, {"__file__": str(init_py)}) except Exception as ex: Log(f"Init: Initializing {self.path!s}... failed") Log(utils.HLine) diff --git a/src/Gui/FreeCADGuiInit.py b/src/Gui/FreeCADGuiInit.py index 90f9edc01e..eba658a363 100644 --- a/src/Gui/FreeCADGuiInit.py +++ b/src/Gui/FreeCADGuiInit.py @@ -295,7 +295,7 @@ class DirModGui(ModGui): try: source = init_gui_py.read_text(encoding="utf-8") code = compile(source, init_gui_py, "exec") - exec(code) + exec(code, {"__file__": str(init_gui_py)}) except Exception as ex: sep = "-" * 100 + "\n" Log(f"Init: Initializing {target!s}... failed\n")