我想在html代码中实现pyscript,例如我想生成图表输出,下面是我的代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>my first pyscript</title>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<py-env>
-numpy
-matplotlib
</py-env>
</head>
<body>
<p id="text"></p>
<div id="plot"></div>
<py-script output ="plot">
import matplotlib.pyplot as plt
import numpy as np
x =np.arange(10,20,0.001)
y =3*x+2
fig,ax =plt.subplots()
ax.scatter(x,y)
fig
<!-- print("hello world")-->
<!-- x =0-->
<!-- pyscript.write("text",x+1)-->
</py-script>
</body>
</html>
但是当我运行代码时,我得到以下错误:
JsException(PythonError: Traceback (most recent call last): File "/lib/python3.10/site-packages/_pyodide/_base.py", line 421, in eval_code CodeRunner( File "/lib/python3.10/site-packages/_pyodide/_base.py", line 237, in __init__ self.ast = next(self._gen) File "/lib/python3.10/site-packages/_pyodide/_base.py", line 141, in _parse_and_compile_gen mod = compile(source, filename, mode, flags | ast.PyCF_ONLY_AST) File "", line 2 import numpy as np IndentationError: unexpected indent )
我不知道html中的pyscript需要缩进,但是这个缩进错误在哪里呢?