brythonmagic
brythonmagic copied to clipboard
brython.js version >= 3.7.x is not working
Since Brython version >= 3.7.x I'm getting the following error:
ReferenceError: $locals___main__ is not defined
<anonymous> brython.js:4
_run_scripts brython.js:4911
brython brython.js:4758
<anonymous> Brython usage in the IPython notebook-Copy1.ipynb:1
jQuery 3
_safe_append outputarea.js:459
append_display_data outputarea.js:666
append_output outputarea.js:346
handle_output outputarea.js:257
output codecell.js:399
_handle_output_message kernel.js:1198
i jQuery
_handle_iopub_message kernel.js:1238
_finish_ws_message kernel.js:1017
_msg_queue kernel.js:1008
promise callback*Kernel.prototype._handle_ws_message kernel.js:1008
i jQuery
start_channels kernel.js:517
_kernel_created kernel.js:412
on_success kernel.js:317
_on_success kernel.js:380
jQuery 6
ajax utils.js:797
restart kernel.js:332
restart_and_resolve notebook.js:2408
click notebook.js:2435
jQuery 10
modal dialog.js:95
_restart_kernel notebook.js:2439
restart_kernel notebook.js:2394
handler actions.js:127
<anonymous> actions.js:917
call actions.js:1019
fun toolbar.js:116
So brython versions >= 3.7.0 could not be used at this moment.
Hi Kiko,
For a basic script such as
print("ok")
Brython generates this code:
var $B = __BRYTHON__;
var _b_ = __BRYTHON__.builtins;
var $locals = $locals___main__
$locals___main__.__package__ = ""
$locals.__annotations__ = $B.empty_dict()
var $top_frame = ["__main__", $locals___main__, "__main__", $locals___main__]
$locals.$f_trace = $B.enter_frame($top_frame)
var $stack_length = $B.frames_stack.length;
try{
;$locals.$line_info = "1,__main__";if($locals.$f_trace !== _b_.None){$B.trace_line()};_b_.None;
$B.$call(_b_.print)("ok");
$B.leave_frame({$locals, value: _b_.None})
}
catch(err){
$B.leave_frame({$locals, value: _b_.None})
throw err
}
In the third line, the code needs a reference to $locals___main__
. In the Brython execution environment, this variable is initialized to an empty Javascript object. Here is a simplified version:
var $locals___main__ = {}
eval(js_code)
I suppose that setting this value in the brythonmagic environment would remove the error message.
Thanks @PierreQuentel
I would give a try!!!!
Thanks for helping on this.
Salut!!