@@ -22,9 +22,9 @@ async function evaluatePython(pyodide, editor, output, session) {
22
22
try {
23
23
result = await pyodide . runPythonAsync ( code , { globals : getSession ( session , pyodide ) } ) ;
24
24
} catch ( error ) {
25
- writeOutput ( output , error ) ;
25
+ writeOutput ( output , new Option ( error . toString ( ) ) . innerHTML ) ;
26
26
}
27
- if ( result ) writeOutput ( output , result ) ;
27
+ if ( result ) writeOutput ( output , new Option ( result ) . innerHTML ) ;
28
28
hljs . highlightElement ( output ) ;
29
29
}
30
30
@@ -91,11 +91,17 @@ async function setupPyodide(idPrefix, install = null, themeLight = 'tomorrow', t
91
91
writeOutput ( output , "Initializing..." ) ;
92
92
let pyodide = await pyodidePromise ;
93
93
if ( install && install . length ) {
94
- micropip = pyodide . pyimport ( "micropip" ) ;
95
- for ( const package of install )
96
- await micropip . install ( package ) ;
94
+ try {
95
+ micropip = pyodide . pyimport ( "micropip" ) ;
96
+ for ( const package of install )
97
+ await micropip . install ( package ) ;
98
+ clearOutput ( output ) ;
99
+ } catch ( error ) {
100
+ clearOutput ( output ) ;
101
+ writeOutput ( output , `Could not install one or more packages: ${ install . join ( ", " ) } \n` ) ;
102
+ writeOutput ( output , new Option ( error . toString ( ) ) . innerHTML ) ;
103
+ }
97
104
}
98
- clearOutput ( output ) ;
99
105
run . onclick = ( ) => evaluatePython ( pyodide , editor , output , session ) ;
100
106
clear . onclick = ( ) => clearOutput ( output ) ;
101
107
output . parentElement . parentElement . addEventListener ( "keydown" , ( event ) => {
0 commit comments