I was having trouble importing local modules, getting a “ModuleNotFoundError.” Sure that I was setting up py-config correctly, I copied and pasted the example scripts from the documentation (see below) and got the same error. Is this a known issue or is it a matter of the documentation lagging behind the latest version a bit?
# data.py
import numpy as np
def make_x_and_y(n):
x = np.random.randn(n)
y = np.random.randn(n)
return x, y
<html>
<head>
<link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
<script defer src="https://pyscript.net/latest/pyscript.js"></script>
</head>
<body>
<h1>Let's plot random numbers</h1>
<div id="plot"></div>
<py-config type="toml">
packages = ["numpy", "matplotlib"]
[[fetch]]
files = ["./data.py"]
</py-config>
<py-script output="plot">
import matplotlib.pyplot as plt
from data import make_x_and_y
x, y = make_x_and_y(n=1000)
fig, ax = plt.subplots()
ax.scatter(x, y)
fig
</py-script>
</body>
</html>
When loading the page, this error is printed
“PythonError: Traceback (most recent call last): File “/lib/python3.10/asyncio/futures.py”, line 201, in result raise self._exception File “/lib/python3.10/asyncio/tasks.py”, line 232, in __step result = coro.send(None) File “/lib/python3.10/site-packages/_pyodide/_base.py”, line 506, in eval_code_async await CodeRunner( File “/lib/python3.10/site-packages/_pyodide/_base.py”, line 357, in run_async coroutine = eval(self.code, globals, locals) File “”, line 2, in ModuleNotFoundError: No module named ‘data’”