PyScript: How to import local libraries?

All the examples I’ve seen show how to include a simple module. How would I import a local library? Every way I try it I get ModuleNotFoundError.

1 Like

Provide more details such as the code and actual error messages. Typically you would specify the modules using <py-env> and then an import statement.

1 Like

I was trying to use pyecore library which is not supported by pyodide.

EDIT: Actually pyecore is available in pyodide…the fist time I tried I got an error and I assumed it was not. But the initial question still remains, suppose I have a custom library just like pyecore.

Project structure:

- index.html
- pyecore/
  - ...


<!DOCTYPE html>
    <link rel="stylesheet" href="" />
    <script defer src=""></script>
        - paths:
          - /
          - /pyecore/
      from test import test
</html> (but also other libraries) import pyecore simply by:

from pyecore.ecore import EClass

The error I get is:
File "", line 1, in File "/home/pyodide/", line 10, in from pyecore.ecore import EClass ModuleNotFoundError: No module named 'pyecore'

1 Like

After a bit more digging I found a workaround mentioned in this forum. There is also an issue submitted on github about this.

The workaround suggested is to make a prebuilt wheel and include it like a normal module.

- ./pyecore.whl