PyScript 使用(1)
今天按照官方文档进行pyscript的调用,发现paths下总是出现问题,于是调试了一下,问题解决了;
# 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/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<py-env>
- numpy
- matplotlib
- paths:
- /data.py <!-- 原demo 内容-->
- /WebPy/pyinweb/data.py <!-- 修改为自己的工程目录 -->
</py-env>
</head>
<body>
<h1>Let's plot random numbers</h1>
<div id="plot"></div>
<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>
在执行的时候访问路径为:http://localhost:63322/WebPy/pyinweb/random_numbers.html, 因此把/data.py 改为/WebPy/pyinweb/data.py, 问题解决
浙公网安备 33010602011771号