I need to use some files in my Pyscript algorithm, and I know Pyscript can´t access local files because of a security issue. But my question is, can I somehow upload those files to a virtual file system, because otherwise I'm going to be unable to run my script. When using the open() function, I'm getting an error where the file isn't found.
1 Answer
If you have the files available "to the network" (either on a web server, or served locally with something like python3 -m http.serve or another simple dev server), you can uses the [files] key in py-config to load those files into the virtual filesystem.
The older [[fetch]] key is also available, but it's a little error-prone due to its complexity and options, so [files] is currently the recommended way forward.
4 Comments
Jeff Glass
Also, from another question you recently asked, it looks like you're still using the
alpha release of pyscript, which has had many releases since then. See the examples at pyscript.github.io/docs/2024.2.1/beginning-pyscript .Jeff Glass
@Wayne does it work if you link directly to the most recent release (
https://pyscript.net/releases/2024.03.2/core.js as of today) instead of /latest?Wayne
Yes, it works with
https://pyscript.net/releases/2024.3.2/core.js , which I suspect is what you meant since that other one is not valid. (Now working here.) Part of the issue is that leaving the plugins directive in py-config caused it to fail silently it seemed. I did notice though you mentioned plugins as an issue in your post about the November overhaul and thought maybe best to try without it. However, I don't see the interactive terminal working ...Wayne
<continued> as spelled out here which made figuring out how to get
Element working again difficult. (I was hoping I could keep trying import statements in an interactive console.) I stumbled through at least importing pydom from pyweb, yet gettting it to toggle visibility of a div didn't seem to work and so I made the div not hidden to get past that small hitch.
.ipynbfile, then download it back to your local system's file system because if something goes kablooie with your browser or you clear the cache, ...