How to import a folder


I was wondering how to import a folder? For example, I have my index file which is located in: /src/website/ and I want to import the /src/ folder? For some reason, in my py-env tag, when I try to import it as ‘- /src/’ it doesn’t actually import. Any ideas on how this is possible? I also have an init file in the location that I want to import.

Do you get any logging to the JS console that might explain?

Here’s the line in the source

Hmm, looking at it a little more, I’m not sure if PyScript at the moment supports importing a local package. Might only be either a PyPI package or local file.

Webservers do not provide the contents of a directory unless configured to do so and the output is generally an HTML page and not something PyScript could parse.

Pyscript does not support loading everything from a directory. You must specify the path to each file to load.

@john.hanley makes a good point. PyScript needs each external file to be declared via before it can be imported. A Python package contains an unknown set of files. Heck, it might contain weird dynamic importlib stuff that have nothing to do with a “file”.

Thus, with the current state of …won’t work.

1 Like

Thank you both! I’ve changed my code to do so, you both saved me 10 hours of figuring it out.