pythonpython-modulepyscriptpyscripter

How to run add absolute path to custom python module/library at Pyscript on web server


I need to run my code from custom library and show it at clientside/browser I have problem with run code Pyscript from custom library when i`m include path (by recommendation https://github.com/pyscript/pyscript/issues/519) at my hosting web side for client

https://test.com/lib/python/example/index.html with code 👇
<html>
<head>
<script defer src="https://pyscript.net/releases/2022.12.1/pyscript.js"></script>
<link rel="stylesheet" href="https://pyscript.net/releases/2022.12.1/pyscript.css"/>
</head>
<body>    

<py-config>
    [[fetch]] 
paths = ["https://test.com/lib/python/example/custom/example.py"] #custom py-module
or 
[[fetch]]
url = "https://test.com/lib/python/example/"
folder = "custom/"
files = ["example.py"]
or
[[fetch]]
path = "lib/python/example/custom/example.py"
uri = "https://test.com/lib/python/example/custom/example.py"

# example.py
/* code file
def hello():
    print("Pyscript")
*/

</py-config>

<py-script>
    import example
    example.hello()
</py-script>
    

</body>
</html>

Paths on server:

with path
|---https://test.com/lib/python/example/custom/
|---------------------------------------------/index.html
|---------------------------------------------/example.py

or
|---https://test.com/lib/python/example/custom/
|---------------------------------------------/index.html
|---------------------------------------------/py/example.py

I have error - (PY1000): Couldn't determine the filename from the path , please supply 'to_file' parameter. 😪

How can i resolve it and run my custom module code by absolutely path to Pyscript on web hosting and show it 😞 ?


Solution

  • <py-config>
      [[fetch]]
      files = ['example.py'] #name of your py-file
      from = '../lib/python/example/custom/py/' #folder where placed your py-file
    </py-config>
    <py-script>
      import example
      example.hello()
    </py-script>