I am trying to import a package supported by pyodide in shinylive under a quarto document. The main reason is I want to load an image using opencv. Firstly, this code:
```{shinylive-python}
#| standalone: true
#| viewerHeight: 420
from shiny import App, render, ui
import numpy as np
import matplotlib.pyplot as plt
import cv2
```
give me the following error:
Error starting app! Traceback (most recent call last): File "", line 202, in _start_app File "/lib/python3.10/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1053, in _gcd_import File "", line 1030, in _find_and_load File "", line 1009, in _find_and_load_unlocked File "", line 688, in _load_unlocked
File "", line 883, in exec_module File "", line 241, in _call_with_frames_removed File "/home/pyodide/app_4mr6ploxwzzzk07rc0d4/app.py", line 2, in import cv2 ModuleNotFoundError: The module 'opencv-python' is included in the Pyodide distribution, but it is not installed. You can install it by calling: await micropip.install("opencv-python") in Python, or await pyodide.loadPackage("opencv-python") in JavaScript See https://pyodide.org/en/stable/usage/loading-packages.html for more details.
I also tried:
```{shinylive-python}
#| standalone: true
#| viewerHeight: 420
from shiny import App, render, ui
import numpy as np
import matplotlib.pyplot as plt
import pyodide_js
await pyodide_js.loadPackage('opencv-python')
import cv2
```
But this gives me the following error:
Traceback (most recent call last): File "", line 202, in _start_app File "/lib/python3.10/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1053, in _gcd_import File "", line 1030, in _find_and_load File "", line 1009, in _find_and_load_unlocked File "", line 688, in _load_unlocked
File "", line 879, in exec_module File "", line 1017, in get_code File "", line 947, in source_to_code File "", line 241, in _call_with_frames_removed File "/home/pyodide/app_4mr6ploxwzzzk07rc0d4/app.py", line 3 await pyodide_js.loadPackage('opencv-python') ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ SyntaxError: 'await' outside function