DOC Complete example for using micropip (#412)

This commit is contained in:
Simon Biggs 2020-05-09 07:22:33 +10:00 committed by GitHub
parent ea74555209
commit c9fd3e1d57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 36 additions and 3 deletions

View File

@ -33,10 +33,43 @@ finished loading:
```
def do_work(*args):
import snowballstemmer
stemmer = snowballstemmer.stemmer('english')
stemmer.stemWords('go goes going gone'.split())
import snowballstemmer
stemmer = snowballstemmer.stemmer('english')
print(stemmer.stemWords('go goes going gone'.split()))
import micropip
micropip.install('snowballstemmer').then(do_work)
```
## Complete example
Adapting the setup from the section on ["using pyodide from
javascript"](./using_pyodide_from_javascript.html) a complete example would be,
```html
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<script type="text/javascript" src="https://pyodide.cdn.iodide.io/pyodide.js"></script>
<script type="text/javascript">
pythonCode = `
def do_work(*args):
import snowballstemmer
stemmer = snowballstemmer.stemmer('english')
print(stemmer.stemWords('go goes going gone'.split()))
import micropip
micropip.install('snowballstemmer').then(do_work)
`
languagePluginLoader.then(() => {
return pyodide.loadPackage(['micropip'])
}).then(() => {
pyodide.runPython(pythonCode);
})
</script>
</body>
</html>
```