I try to create a python .exe to allow anyone on my company to run it.
However, my project uses jpype to include java classes, you can see below my file callback.py
:
from dash.dependencies import Input, Output
from dash_app import app
import jpype
import jpype.imports
from jpype.types import *
import math
# Launch JVM
jpype.startJVM('-ea', classpath=["project.jar"])
Constants = JClass("com.mypackage.Constants")
@app.callback(
Output('output-div', 'children'),
[Input('input-box', 'value')]
)
def update_output(value):
print(Constants.SMALLEST_DISTANCE)
return f'Vous avez entré : {value}'
app.clientside_callback(
"""
function() {
return navigator.permissions.query({name:'notifications'})
}
""",
Output("notification-permission", "data"),
Input("notify-btn", "n_clicks"),
prevent_initial_call=True,
)
app.clientside_callback(
"""
function(result) {
if (result.state == 'granted') {
new Notification("Dash notification", { body: "Notification already granted!"});
return null;
} else if (result.state == 'prompt') {
return new Promise((resolve, reject) => {
Notification.requestPermission().then(res => {
if (res == 'granted') {
new Notification("Dash notification", { body: "Notification granted!"});
resolve();
} else {
reject(`Permission not granted: ${res}`)
}
})
});
} else {
return result.state;
}
}
""",
Output("notification-output", "children"),
Input("notification-permission", "data"),
prevent_initial_call=True,
)
my dash_app.py
:
from dash import *
import dash_html_components as html
app = Dash(__name__)
from callback import *
app.layout = html.Div([
html.H1('Exemple de Dash App'),
html.Div('Entrez du texte :'),
dcc.Input(id='input-box', type='text', value=''),
html.Div(id='output-div'),dcc.Store(id="notification-permission"),
html.Button("Notify", id="notify-btn"),
html.Div(id="notification-output")
])
if __name__ == '__main__':
app.run_server(host='127.0.0.1', port=8050, debug=False, use_reloader=False)
and this is my dash_app.spec
:
# -*- mode: python ; coding: utf-8 -*-
a = Analysis(
['dash_app.py'],
pathex=[],
binaries=[('project.jar', '.')],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=0,
)
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='dash_app',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
to create my .exe i use : pyinstaller dash_app.spec
the .exe works on my machine but on another machine i have this :
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "PyInstallerloaderpyimod02_importers.py", line 419, in exec_module
File "callback.py", line 10, in <module>
Constants = JClass("com.mypackage.Constants")
File "jpype_jclass.py", line 99, in __new__
TypeError: Class com.mypackage.Constants is not found
[21812] Failed to execute script 'dash_app' due to unhandled exception!