Search code examples
pythonpyscript

Pyscript over CDN get exception: JsException(PythonError: Traceback (most recent call last)


I want to try pyscript and immediately run into this error. What have I done?

HTML

<!doctype html>
 <html lang="en">
 <head>
   <meta charset="utf-8">
   <title>Py Script</title>
   <meta name="description" content="HTML">
   <meta name="author" content="lowrey">
   <link rel="stylesheet"
   href="https://pyscript.net/alpha/pyscript.css" />
   
 </head>
 <body>
     <py-script>print("Hello Anaconda").</py-script>
    <script defer
    src="https://pyscript.net/alpha/pyscript.js"></script>   
 </body>
 </html>

Error/exeption

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 1 print("Hello Anaconda"). ^ SyntaxError:
invalid syntax )

Pyscript Docu: https://anaconda.cloud/pyscript-python-in-the-browser


Solution

  • You have a Python syntax error. The . (dot) is outside the string.

    Change this line:

    <py-script>print("Hello Anaconda").</py-script>
    

    To this:

    <py-script>print("Hello Anaconda.")</py-script>