Last active
December 4, 2023 09:43
-
-
Save jcayzac/a36196d9c06ff5526081f2b3c66944b1 to your computer and use it in GitHub Desktop.
Running Python code from Deno (no python installed).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Object.defineProperty(self, 'document', { value: {}, }) | |
self.location = new URL('file:///nowhere') | |
import 'https://cdn.jsdelivr.net/pyodide/v0.24.1/full/pyodide.asm.js' | |
const { loadPyodide } = await import('https://cdn.jsdelivr.net/pyodide/v0.24.1/full/pyodide.mjs') | |
const pyodide = await loadPyodide() | |
await pyodide.loadPackage('micropip') | |
const micropip = pyodide.pyimport('micropip') | |
await Promise.all([ | |
'pandas', | |
'jupyterlite_core', | |
].map(pkg => micropip.install(pkg))) | |
const src = ` | |
import numpy as np | |
import pandas as pd | |
dates = pd.date_range("20130101", periods=6) | |
df = pd.DataFrame(np.random.randn(6, 4), index=dates, columns=list("ABCD")) | |
print(df) | |
#from jupyterlite_core.addons.base import * | |
#from jupyterlite_core.app import main | |
#main() | |
` | |
await pyodide.runPython(src) | |
console.log('done') | |
// A B C D | |
// 2013-01-01 -0.417943 0.900617 1.491309 1.702334 | |
// 2013-01-02 1.881831 0.228170 0.371837 -0.153105 | |
// 2013-01-03 -1.874005 -0.757313 -0.843753 -0.074524 | |
// 2013-01-04 -0.432489 -0.128138 -0.947358 -0.237271 | |
// 2013-01-05 -1.005065 1.134110 0.034008 -0.326109 | |
// 2013-01-06 -0.515446 -0.590442 1.567111 -0.146344 | |
// done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment