posit-dev / py-shiny

Shiny for Python
https://shiny.posit.co/py/
MIT License
1.1k stars 62 forks source link

error importing ruamel, a package included in pyodide #1463

Open JoseBlanca opened 2 weeks ago

JoseBlanca commented 2 weeks ago

Hi, I am developing a shinylive application. My app requires msprime, that in turn requires ruaml.yaml. Both packages are included in pyodide, but I'm getting this error.

Error starting app!

Traceback (most recent call last): File "", line 386, in _start_app File "/lib/python311.zip/importlib/init.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "", line 1209, in _gcd_import File "", line 1181, in _find_and_load File "", line 1152, in _find_and_load_unlocked File "", line 690, in _load_unlocked File "", line 940, in exec_module File "", line 241, in _call_with_frames_removed File "/home/pyodide/app_ku1imi7k5mubdrv6ryn1/app.py", line 4, in import msprime File "/lib/python3.11/site-packages/msprime/init.py", line 36, in from msprime.ancestry import ( File "/lib/python3.11/site-packages/msprime/ancestry.py", line 41, in from . import demography as demog File "/lib/python3.11/site-packages/msprime/demography.py", line 43, in import demes File "/lib/python3.11/site-packages/demes/init.py", line 9, in from .demes import ( File "/lib/python3.11/site-packages/demes/demes.py", line 13, in from .load_dump import dumps as demes_dumps File "/lib/python3.11/site-packages/demes/load_dump.py", line 11, in import ruamel.yaml ModuleNotFoundError: The module 'ruamel-yaml' is included in the Pyodide distribution, but it is not installed. You can install it by calling: await micropip.install("ruamel-yaml") in Python, or await pyodide.loadPackage("ruamel-yaml") in JavaScript See https://pyodide.org/en/stable/usage/loading-packages.html for more details.

I have tried to include ruamel.yaml in the app requirements.txt file, with that has not solved the error. Should I really try to intall it using micropip? In that case, where should I put that code in the app?

I have tried putting in the top of app.py the lines:

import micropip await micropip.install("ruamel.yaml")

But I get the error:

SyntaxError: 'await' outside function

Best regards,

Jose Blanca

JoseBlanca commented 2 weeks ago

Hi,

I've manage to make it (kind of) work.

The library that i'm really trying to use is msprime, but msprime depends on ruamel.yaml. What I've done is directly importing ruamel.yaml at the start of app.py Here's the code.

from shiny import App, reactive, render, ui import pandas from ruamel.yaml import YAML import msprime

That works, or at least the app is now loading in the browser and is using ruamel.yaml. In the shell that is running the server there are several BrokenPipeError. Also, in the App page, although it loads, a spinning blue circle appears and never goes away. (Although maybe these problems are not related with msprime and ruaml, I'm not sure). Best,

Jose Blanca