Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can one load custom wheel files? (pyodide-built; out of tree) #5

Open
zachcp opened this issue Nov 21, 2022 · 2 comments
Open

Can one load custom wheel files? (pyodide-built; out of tree) #5

zachcp opened this issue Nov 21, 2022 · 2 comments

Comments

@zachcp
Copy link

zachcp commented Nov 21, 2022

Hi Team Py-Shiny,

This is really amazing work; thank you. I am wondering if there current the capability to sideload pyodide-built .whl into the environment. I see something similar is done with the requirements.txt file in the py-shiny repo and would hope to be able to do the something similar here.

Thanks,
zach cp

@wch
Copy link
Collaborator

wch commented Nov 21, 2022

Yes, you can do it by adding a requirements.txt file with something like this:

```{shinylive-python}
#| standalone: true
## file: app.py

<App contents here>

## file: requirements.txt
mypackage
mypackage2==1.01
```

Note that, by default it will install the packages from PyPI, but you can also specify a URL. See the live example here:
https://shinylive.io/py/examples/#extra-packages

@zachcp
Copy link
Author

zachcp commented Nov 22, 2022

Thank you, thats fantastic.

And what would you recommend if the wheels are local. For example, in the standalone shinylive context I can specify a local file (or copy it into /shinylive/pyodide) but that won't work here.

# example requirements.txt
./packages/pack1.whl
./packages/dep1.whl
./packages/dep2.whl

I also notice this route won't work with pyodide packages that are not in the core shinylive distribution. For example, the biopython requirement is not followed and will throw an error.

#| standalone: true
## file: app.py

from Bio.Seq import Seq
print(Seq("AACTG")) 

## file: requirements.txt
biopython

This will yield the following:

Traceback (most recent call last):
  File "<exec>", 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 "<frozen importlib._bootstrap>", line 1050, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 688, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/pyodide/app_zmur716jvalmlsxccz4r/app.py", line 2, in <module>
    from Bio import SeqIO
ModuleNotFoundError: No module named 'Bio'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants