2

I have a github repo that is hosted on GitHub Pages (project site). I’m migrating a small PyScript demo to GitHub Pages and hitting 404s when preloading files via <py-config>. This works locally and also worked previously with an older PyScript alpha*. The github repo contains an index.html and static files live in a src/ folder. I use PyScript, a recent release, 2025.10.3.

For illustration, this is how my code looks:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>demo</title>
    <!--  -->
  <link rel="stylesheet" href="https://pyscript.net/releases/2025.10.3/core.css" />
  <script type="module" src="https://pyscript.net/releases/2025.10.3/core.js"></script>
<py-config>
{
  "packages": ["numpy"],
  "files": {
    "/src/module.py": "./module.py",
    "/src/data.npz": "src/data.npz"
  },
  "paths": ["/src"]
}
</py-config>
</head>

<py-script>
import module          # expected to work because it is on sys.path
import numpy as np
arr = np.load("/src/data.npz")   #e.g.
print("OK")
</py-script>

</html>

All works ok when I run it locally, the module and the file get both loaded. However, when I push it to GitHub Pages, the network panel shows 404s for those files. The browser tries URLs that don’t exist for the deployed site (e.g., resolving from the domain root, or from the wrong folder, or from hidden files -- the repo itself is not public). What is the correct way of dealing with the files? How can I serve them or source them without absolute paths (I would like to avoid putting out the files and hardwiring the path) in the same way as it used to in pyscript?

Thanks.

*That was implemented as:

    <py-env>
      - numpy
      - paths:
        - src/module.py
        - src/data.npz
    </py-env>
4
  • 2
    Just make the relative path, not absolute. Try this: <py-config> { "packages": ["numpy"], "files": { "src/module.py": "src/module.py", "src/data.npz": "src/data.npz" }, "paths": ["src"] } </py-config> Commented Oct 30 at 18:11
  • Hi @colonel, thanks, I don't see a difference between the paths I have and you write, what do you mean? Commented Oct 30 at 18:16
  • 2
    The difference is the leading /. /src/... means “from the site root”, which breaks on GitHub Pages. src/... means “relative to index.html”, which works in GitHub Pages project sites. So remove backslash, check my earlier comment Commented Oct 30 at 18:27
  • Oh, I see, my bad, thanks @colonel! This stupid bug nagged me for hours. Would you like to write it up as an answer? I would love to give you the credit. Commented Oct 31 at 8:23

1 Answer 1

2

Your code works because the browser serves your folder root directly. On GitHub Pages, your files are not being requested from the correct URL, so the preload fetch fails that why you got 404.

Just make paths relative, not absolute:

<py-config>
{
  "packages": ["numpy"],
  "files": {
    "src/module.py": "src/module.py",
    "src/data.npz": "src/data.npz"
  },
  "paths": ["src"]
}
</py-config>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.