Eel version
$ pip freeze | grep -i eel
Eel==0.12.3
Describe the bug
When I run the built package, it starts properly. But within the application, it says
To Reproduce
Steps to reproduce the behavior:
$ git clone https://github.com/MartinThoma/write-math-eel.git && cd write-math-eel
$ python -m venv venv
$ source venv/bin/activate
$ pip install -r requirements.txt
$ pip install pyinstaller
$ python -m eel main.py web --onefile --noconsole
$ cd dist
$ ./main
# A window pops up - draw something in it, e.g. the greek letter "alpha"
# Then:
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 854, in gevent._gevent_cgreenlet.Greenlet.run
File "venv/lib/python3.8/site-packages/eel/__init__.py", line 259, in _process_message
File "main.py", line 43, in worker
File "venv/lib/python3.8/site-packages/hwrt/classify.py", line 92, in classify_segmented_recording
File "venv/lib/python3.8/site-packages/hwrt/classify.py", line 28, in __init__
File "venv/lib/python3.8/site-packages/hwrt/utils.py", line 451, in load_model
File "tarfile.py", line 1599, in open
File "tarfile.py", line 1664, in gzopen
File "gzip.py", line 173, in __init__
FileNotFoundError: [Errno 2] No such file or directory: '/tmp/_MEIY94PgK/hwrt/misc/model.tar'
2020-06-21T19:56:17Z <Greenlet at 0x7f0bd34bb040: _process_message({'call': 1.9957332098804472, 'name': 'worker', 'ar, <geventwebsocket.websocket.WebSocket object at 0x7)> failed with FileNotFoundError
The hwrt/misc/model.tar comes from those two lines:
model_path = pkg_resources.resource_filename("hwrt", "misc/")
model_file = os.path.join(model_path, "model.tar")
Expected behavior
A list of recognized symbols should have appeared, similar as on write-math.com
Desktop (please complete the following information):
This might not be a bug in Eel. Maybe I use pyinstaller the wrong way as I'm very new to it. However, I would appreciate it if you could point me into the right direction 馃檹
Hi @MartinThoma. I think you need to include this as extra data when you package it up. See https://github.com/samuelhwilliams/Eel#building-distributable-binary-with-pyinstaller for details (and link to PyInstaller docs).
I think you need to add the --add-data flag when you run the Eel packager. I'm not sure exactly what path you need to supply - you might know better there than me. ~Possibly it's --add-data hwrt/misc/model.tar - but I'm guessing. :)~ << It wasn't that.
Let me know how you get on!
@MartinThoma - I had a bit of a dig and came up with this build script that will work out the file path for model.tar and include it in the package.
build.py (assuming Python 3.6+)
import pkg_resources as pkg
import PyInstaller.__main__ as pyi
import os
from argparse import ArgumentParser
eel_js_file = pkg.resource_filename("eel", "eel.js")
js_file_arg = f"{eel_js_file}{os.pathsep}eel"
web_folder_arg = f"web{os.pathsep}web"
model_tar_file = pkg.resource_filename("hwrt", os.path.join("misc", "model.tar"))
model_file_arg = f"{model_tar_file}{os.pathsep}{os.path.join('hwrt', 'misc')}"
pyinstaller_args = [
"--hidden-import",
"bottle_websocket",
"--add-data",
js_file_arg,
"--add-data",
web_folder_arg,
"--add-data",
model_file_arg,
"main.py",
"--onefile",
]
print("Running:\npyinstaller", " ".join(pyinstaller_args), "\n")
pyi.run(pyinstaller_args)
Feel free to copy that into build.py and run it with python build.py - let me know if it works & hope it helps!
It works! You're so awesome, @samuelhwilliams ! Would it be ok for you if I added this to the project? If you want, I can add an author comment (whatever you would like) there :-)
Feel free - of course. Attribution would be nice but not necessary. Glad it helped!
https://github.com/MartinThoma/write-math-eel/blob/master/build.py - let me know if I should change it in any way :-) :hugs:
More than enough - thanks! 馃憤
Most helpful comment
@MartinThoma - I had a bit of a dig and came up with this build script that will work out the file path for
model.tarand include it in the package.build.py (assuming Python 3.6+)
Feel free to copy that into
build.pyand run it withpython build.py- let me know if it works & hope it helps!