Skip to content

Commit 3bf810c

Browse files
committed
Fixing imports
1 parent 47a9785 commit 3bf810c

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

script.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,31 @@ const state = {
1313
codeMirrorEditor: null
1414
};
1515

16+
// ========================================
17+
// PACKAGES TO PRELOAD
18+
// Uncomment packages you need for your code
19+
// ========================================
20+
const PACKAGES_TO_LOAD = [
21+
// Common packages
22+
'numpy',
23+
// 'pandas',
24+
// 'matplotlib',
25+
// 'scikit-learn',
26+
// 'scipy',
27+
28+
// Progress bars
29+
'tqdm',
30+
31+
// Requests/HTTP
32+
// 'requests',
33+
// 'beautifulsoup4',
34+
35+
// Other
36+
// 'pillow',
37+
// 'sympy',
38+
// 'networkx',
39+
];
40+
1641
// Pyodide Management
1742
async function initPyodide() {
1843
if (state.pyodide) return state.pyodide;
@@ -37,6 +62,30 @@ async function initPyodide() {
3762
await state.pyodide.loadPackage('micropip');
3863
console.log('Micropip loaded');
3964

65+
// Load pre-defined packages
66+
if (PACKAGES_TO_LOAD.length > 0) {
67+
statusEl.innerHTML = `<div class="loader-small"></div><span>Loading packages: ${PACKAGES_TO_LOAD.join(', ')}...</span>`;
68+
69+
for (const pkg of PACKAGES_TO_LOAD) {
70+
try {
71+
console.log(`Loading ${pkg}...`);
72+
await state.pyodide.loadPackage(pkg);
73+
console.log(`✓ ${pkg} loaded`);
74+
} catch (err) {
75+
console.log(`${pkg} not in Pyodide, trying micropip...`);
76+
try {
77+
await state.pyodide.runPythonAsync(`
78+
import micropip
79+
await micropip.install('${pkg}')
80+
`);
81+
console.log(`✓ ${pkg} installed via micropip`);
82+
} catch (micropipErr) {
83+
console.warn(`✗ Could not load ${pkg}:`, micropipErr);
84+
}
85+
}
86+
}
87+
}
88+
4089
statusEl.style.display = 'none';
4190
state.pyodideLoading = false;
4291
return state.pyodide;

0 commit comments

Comments
 (0)