-
Notifications
You must be signed in to change notification settings - Fork 184
Vue components unable to find template vue files when using frozen/pyinstaller application on Windows #825
Description
I have been using PyInstaller to create an executable .exe file for my solara application, and that has, in general, worked very well. However, recently I started using the Menu component and that caused the following issue when I was building the application to an executable using PyInstaller:
Traceback (most recent call last):
File "reacton\core.py", line 388, in _create_widget
File "ipyvue\VueTemplateWidget.py", line 144, in __init__
File "solara\server\patch.py", line 250, in wrapper
File "ipyvue\Template.py", line 47, in get_template
FileNotFoundError: [Errno 2] No such file or directory: 'solara\\lab\\components\\menu.vue'
On the other hand, the solara application was working completely fine if I ran it as a normal python program from the terminal.
I belive I have traced the problem to the component_vue decorator which in turn calls a wrapper function that uses inspect.getfile to get the path to the file where the decorated function is defined. It looks like follows:
def _widget_vue(vue_path: str, vuetify=True) -> Callable[[Callable[P, None]], Type[v.VuetifyTemplate]]:
def decorator(func: Callable[P, None]):
class VuetifyWidgetSolara(v.VuetifyTemplate):
template_file = (inspect.getfile(func), vue_path)
class VueWidgetSolara(vue.VueTemplate):
template_file = (inspect.getfile(func), vue_path)
base_class = VuetifyWidgetSolara if vuetify else VueWidgetSolara
widget_class = _widget_from_signature("VueWidgetSolaraSub", base_class, func, "vue_")
return widget_class
return decoratorWe can see here that the call inspect.getfile(func) is expected to provide the full absolute path to the file. When not using a frozen executable on Windows (or using some other platform like Mac), this works as expected, but when using the frozen executable on Windows, the inspect.getfile(func) will return a relative path, leading the the vue file not being found.
A simple solution (which I have tested already) is to surround the inspect.getfile(func) with os.path.abspath, as this will correctly resolve the path, no matter if the inspect module returns a relative path, or not.