Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python imprt own function in html page

knowing that with <py-config> and <py-script> can execute python code in html


However, importing own function facing error
(PY1001): Unable to install package(s) 'bread'. Reason: Can't find a pure Python 3 Wheel for package(s) 'bread'. See: https://pyodide.org/en/stable/usage/faq.html#micropip-can-t-find-a-pure-python-wheel for more information.

  • html script
<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 <u><label id="AAA"></label></u> </p></b>
    <br>
  
    <py-config>

      packages = ["bread"]
    </py-config>


    <py-script>
        import bread.py
        bread.fun_1()

    </py-script>
  </body>
</html>
  • own python script "bread.py"
def fun_1():
    print("this is bread")

(pic) the result screenshot for above code

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel


if I import my own function in another .py script is working, but do the same thing into html not works
(pic) the result that import my own function in another .py script is fine

I read through the link system recommend link, and link but I can’t find out the solution myself, that I need a hand for this problem, thanks

>Solution :

The reason you are getting the error is that PyScript thinks you want to import a third-party package.

To import your custom modules, use [[fetch]] in your <py-config> and replace packages with files.


<py-config>
  [[fetch]]
  files = ["./bread.py"]
</py-config>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading