Hi all,
Can I read a csv from disk into pandas? When I hard-link to the file, it says it can’t find the file. If I do os.getcwd(), I get /home/pyodide, which does not exist. All the examples I can find on the website either simulate data or grab it from the web.
/home/pyodide
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 5, in File "/lib/python3.10/site-packages/pandas/util/_decorators.py", line 311, in wrapper return func(*args, **kwargs) File "/lib/python3.10/site-packages/pandas/io/parsers/readers.py", line 680, in read_csv return _read(filepath_or_buffer, kwds) File "/lib/python3.10/site-packages/pandas/io/parsers/readers.py", line 575, in _read parser = TextFileReader(filepath_or_buffer, **kwds) File "/lib/python3.10/site-packages/pandas/io/parsers/readers.py", line 933, in __init__ self._engine = self._make_engine(f, self.engine) File "/lib/python3.10/site-packages/pandas/io/parsers/readers.py", line 1217, in _make_engine self.handles = get_handle( # type: ignore[call-overload] File "/lib/python3.10/site-packages/pandas/io/common.py", line 789, in get_handle handle = open( FileNotFoundError: [Errno 44] No such file or directory: '/home/david/pyscript-main/pyscriptjs/public/voice_data.csv' )
Same issue with me. The CSV file is placed in the same directory as that of the HTML file and it cannot be handled by PyScript? Is there any particular place we need to place the CSV file in? I get the File Not Found error as well.
The python code (and all browser runtime) runs in a sandbox with a virtual or “fake” filesystem, not the real local filesystem. This is a safety feature of browsers, to stop downloaded scripts from being able to read your local data. None of the os module’s features will behave as you expect them to.
If you are hosting your own CSV file in a directory with the HTML, you can probably do an HTTP fetch, as in the examples, but with a filepath like “./voice_data.csv” - i.e., relative to the location of the HTML. It the CSV file is remote, it needs to be on a server set up to allow CORS from any location.
I am getting error now
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 1, in ModuleNotFoundError: No module named ‘altair’ )
If I remove path line and df lines from the script code is working… Basically, I took working example of altair.html and introducing reading data from local csv file…