Joy 宇 2023-01-12 09:07 采纳率: 77.8%
浏览 41
已结题

(python website) 网頁从其他 python 脚本获取输出, 遇 model not found error

根据文章 https://stackoverflow.com/questions/6086047/get-output-of-python-script-from-within-python-script

我创建了 在线网页 (.html) 运行其他 .py 脚本,也就是 import 自己的脚本,结果遇 model not found error

逻辑上似乎 python 代码没问题,可能是设置错误或其他我自己没有想到的问题

  • printbob.py
import sys

def main(args):
    for arg in args:
        print(arg)

if __name__ == '__main__':
    main(sys.argv)
  • test_0109_003.html
<html>
    <head>
      <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
      <script defer src="https://pyscript.net/latest/pyscript.js"></script>
    </head>
  <body>
    <b><p>title test 1.10-test_get_ print  </p></b>
    <br>


  
    <py-script>
      import printbob

      printbob.main('arg1 arg2 arg3 arg4'.split(' '))
      
    </py-script>
  </body>
</html>
  • (pic 01) 网站显示结果

    enter image description here


  • (pic 02)确认有把 .py 和 .html 脚本放在 WinSCP,在线主机系统,但 import model not found

    enter image description here

那么该如何解决这个问题

  • 写回答

1条回答 默认 最新

  • machineShunMing 2023-01-15 11:03
    关注
    <html>
      <head>
        <link rel="stylesheet" href="https://pyscript.net/latest/pyscript.css" />
        <script defer src="https://pyscript.net/latest/pyscript.js"></script>
      </head>
      <body>
        <py-script src="1.py">
       
        </py-script>
        
      </body>
    </html>
    

    1.py

    args='arg1 arg2 arg3 arg4'.split(' ')
    for arg in args:
            print(arg)
     
    

    试试看把脚本引入进来,参考https://docs.pyscript.net/latest/reference/elements/py-script.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论 编辑记录

报告相同问题?

问题事件

  • 系统已结题 2月7日
  • 已采纳回答 1月30日
  • 创建了问题 1月12日

悬赏问题

  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题