I am using Pyscript in my html files for interactive integration testing.
I figured out how to import files and additional modules, and it is working great.
However, I am not able to use relative imports in my files. Is that unsupported?
For example, I have this file structure:
index.html
|-scripts
| - a.py
| - b.py
| - __init__.py
The file scripts/b.py
uses a relative import:
# file: b.py
from .a import my_function_a
In my index.html, I do this:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<py-env>
- paths:
- /scripts/a.py
- /scripts/b.py
</py-env>
</head>
<body>
<py-script>
from a import my_function_a
from b import my_function_b
...
</py-script>
</body>
</html>
I am using a webserver to load it, and it gives this error:
Python exception:
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 "<exec>", line 8, in <module>
File "/home/pyodide/b.py", line 12, in <module>
from .a import my_function_a
ImportError: attempted relative import with no known parent package