pyscript: Directory recognition problem
Hello guys, I’m not sure if it’s a mistake or if I’m doing something wrong. Can anybody help me?
The function below works well on the console. But when I try to print using PyScript and the Live Server extension, I get the following error:
with open(r"C:\Python\readme.txt") as f:
lines = f.readlines()
print(lines)
Console print: ['Text line 1\n', 'Text line 2\n', 'Text line 3']
Error on Browser: JsException(PythonError: Traceback (most recent call last): File “/lib/python3.10/site-packages/_pyodide/_base.py”, line 429, in eval_code .run(globals, locals) File “/lib/python3.10/site-packages/_pyodide/_base.py”, line 300, in run coroutine = eval(self.code, globals, locals) File “”, line 12, in FileNotFoundError: [Errno 44] No such file or directory: ‘C:\Python\readme.txt’ )
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 15 (5 by maintainers)
The error you are receiving is that pyscript cannot read your “readme.txt” file. This is a security feature of your web browser (don’t want some javascript reading your personal files do you?).
Please take a look at the image below:
The “file system” is from emscripten (think of it as a web assembly “container”) to get your files onto this “container” you need to upload them. One method of achieving this is to create a form on your page and write the raw bytes to a file.
You can read the emscripten file system API documentation here
As you can see in the architecture above, pyscript is built on top of pyodide which includes the emscripten “container”. The file system you are seeing when you run those python commands is the file system of emscripten.
This file system is ephemeral and lives entirely in your web browser.