kkinder / puepy

Python+Webassembly Frontend Framework via PyScript
https://puepy.dev
Apache License 2.0
218 stars 9 forks source link

Trying to add beautiful soup as per tutorial fails in error #10

Closed Code4SAFrankie closed 4 months ago

Code4SAFrankie commented 4 months ago

The tutorial https://docs.puepy.dev/pypi-libraries.html#pypi-libraries-when-using-cpython-pyodide gives this error:

Traceback (most recent call last):
  File "/lib/python312.zip/_pyodide/_base.py", line 502, in eval_code
    .run(globals, locals)
     ^^^^^^^^^^^^^^^^^^^^
  File "/lib/python312.zip/_pyodide/_base.py", line 340, in run
    coroutine = eval(self.code, globals, locals)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<exec>", line 2, in <module>
ModuleNotFoundError: No module named 'bs4'
The module 'beautifulsoup4' is included in the Pyodide distribution, but it is not installed.
You can install it by calling:
  await micropip.install("beautifulsoup4") in Python, or
  await pyodide.loadPackage("beautifulsoup4") in JavaScript
See https://pyodide.org/en/stable/usage/loading-packages.html for more details.

pyscript.json:

{
  "name": "PuePy Tutorial",
  "debug": true,
  "packages": [
    "./puepy-0.3.3-py3-none-any.whl",
    "beautifulsoup4"
  ],
  "js_modules": {
    "main": {
      "https://cdn.jsdelivr.net/npm/morphdom@2.7.2/+esm": "morphdom"
    }
  }
}

index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <title>PuePy Hello, World</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <!-- Load PyScript from CDN -->
    <link rel="stylesheet" href="https://pyscript.net/releases/2024.6.2/core.css">
    <script type="module" src="https://pyscript.net/releases/2024.6.2/core.js"></script>
</head>
<body>
    <!-- Where application is mounted -->
    <div id="app"></div>

    <!-- PyScript Config -->
    <script type="py" src="./hello.py" config="./pyscript.json"></script>
</body>
</html>
kkinder commented 4 months ago

I'm able to reproduce that error if I remove "beautifulsoup4" from the config file's packages section.

Could it be that the pyscript.json file is cached or you're pointing to a different one? You can see the actual working example here, so presumably it works: https://kkinder.pyscriptapps.com/puepy-tutorial/latest/tutorial/08_libraries/index.html

Code4SAFrankie commented 4 months ago

Changed to this error when renaming config file to avoid caching (your example url works though):

Cookie “__cf_bm” will soon be rejected because it is foreign and does not have the “Partitioned“ attribute. 2 [core.css](https://pyscript.net/releases/2024.6.2/core.css)
Installing beautifulsoup4 (latest) from https://micropython.org/pi/v2 to /lib [_io.js:31:20](https://pyscript.net/releases/node_modules/polyscript/esm/interpreter/_io.js)
Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user’s experience. For more help https://xhr.spec.whatwg.org/#sync-warning [micropython.mjs:1:75261](https://cdn.jsdelivr.net/npm/@micropython/micropython-webassembly-pyscript@1.24.0-preview-47/micropython.mjs)
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://micropython.org/pi/v2/package/py/beautifulsoup4/latest.json. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 404.

Uncaught (in promise) DOMException: A network error occurred.
    call1 micropython.mjs:1
    invoke_iiii micropython.mjs:1
    invoke_iiii micropython.mjs:1
    invoke_iiiii micropython.mjs:1
    invoke_iiiii micropython.mjs:1
    invoke_iiiii micropython.mjs:1
    invoke_iiiii micropython.mjs:1
    createExportWrapper micropython.mjs:1
    ccall micropython.mjs:1
    obj [micropython.mjs:1](https://cdn.jsdelivr.net/npm/@micropython/micropython-webassembly-pyscript@1.24.0-preview-47/micropython.mjs)
    obj micropython.mjs:1
    nt micropython.js:121
micropython.mjs:1

​
Code4SAFrankie commented 4 months ago

Sorry got it to work after the caching fix. Also had mpy instead of py.