Custom Python package build errors

I have a Python package that renders Markdown files in a repo to a static html output directory. This works using Netlify, and GitHub or GitLab pages. I have read some of the documentation but I cannot find an example that seems to match how this PyPI package, currently named nxc works.
The basic steps are:

  • fetch the repo contents
  • cd to a working directory and
    • pip install -r requirements and then run this command:
      `nxc build -i … -o ./output --lunr --commits
  • the result is a functional static website in the ./output/ directory

the current behavior fails with this error:

sh: line 1: python: command not found
Error: Command “cd .nxc && npm install && python -m pip install -r requirements.txt && nxc build -i … -o ./output --lunr --commits” exited with 127

I am pretty sure the vercel.json file I am using is at fault, and I am also sure that I do not have a good understanding about how to set things up here. my more or less trial and error vercel.json is here:
{
“version”: 2,
“buildCommand”: “cd .nxc && npm install && python3 -m pip install -r requirements.txt && nxc build -i … -o ./output --lunr --commits”,
“outputDirectory”: “.nxc/output”,
“routes”: [
{
“src”: “/(.*)”,
“dest”: “/$1”
}
],
“env”: {
“NODE_VERSION”: “16”
}
}

any help is appreciated, especially where to learn more about how to use Vercel.

thanks, Bill Anderson

Deployment URL or Custom Domain:
Environment (local, preview, production):
Project Framework:
Build Settings:
  Framework Preset:
  Build Command (if not default):
  Output Directory (if not default):
  Install Command (if not default):
Node/Runtime Version:
Package Manager:
Relevant Packages:

Hi, @band101! Welcome to the Vercel Community :smiley: It’s great to have you here.

To deploy your Python-based static site generator on Vercel, we need to make some adjustments to your setup. You can modify your vercel.json file to properly handle your project:

 {{
  "version": 2,
  "builds": [
    {
      "src": "build.sh",
      "use": "@vercel/static-build",
      "config": {
        "distDir": ".nxc/output"
      }
    }
  ],
  "routes": [
    {
      "src": "/(.*)",
      "dest": "/$1"
    }
  ]
}

  1. We’re using the @vercel/static-build builder, which allows us to run custom build scripts.
  2. The builds section points to our build.sh script.
  3. The distDir config tells Vercel where to find the built static files.

You can also create build.sh file in the root of your project with the following content:

#!/bin/bash

# Rest of the script...

# Install Python
curl -L https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-Linux-x86_64.sh -o miniforge.sh
bash miniforge.sh -b -p $HOME/miniforge
export PATH=$HOME/miniforge/bin:$PATH

# Install dependencies and run build
cd .nxc
pip install -r requirements.txt
nxc build -i ... -o ./output --lunr --commits

Make sure your requirements.txt file is in the .nxc directory and includes all necessary dependencies, including your nxc package. If you have any npm dependencies, you should create a package.json file in the .nxc directory and list them there.

To learn more about deploying Python projects on Vercel, you can refer to these resources:

  1. Vercel Python Runtime: https://vercel.com/docs/concepts/functions/serverless-functions/runtimes/python
  2. Vercel Build Step: https://vercel.com/docs/concepts/projects/project-configuration#build-step
  3. Vercel Configuration Reference: https://vercel.com/docs/configuration

Let us know how you get on!

1 Like

thanks so much for the reply. i think i understand the json file.

vercel- cli deploy ends up yielding a 404 at the Inspect URL
so i am not sure what to look at next.

the nxc build command can put the output in any directory; maybe there is a better choice?

the build.sh file makes sense. is the line ‘# Rest of the script…’ a placeholder for some other required steps?

It’s just space for anything else you may need :slight_smile: Feel free to remove!

This makes sense to me - where would you put it?

Have you got any error logs you can share with us?

We also have this community post which may be helpful for such errors:

thanks again for the reply.
i can not see anything helpful in the build log as it is now.
I will:
(1) run vercel-cli commands with ‘-d’ flag
(2) look at the 404 error page (again)

i will let you know what i observe.

1 Like

pawlean, thanks again.

i needed to add npm ci to the build.sh file.

1 last Q: the build.sh command file have any name i choose?

thanks again, and my problem is solved. yay!

-Bill

1 Like

Yes! As long as you call the file correctly, it shouldn’t be a problem.

Great to hear, see you around the community :smile:

If you want, feel free to share your project with us in the Community category. :open_hands:

1 Like

not really an error, but an observation.
when the build.sh runs it creates a miniforge.sh file, and after vercel build is runs the repository has package.json and the lock file. all 3 of these files show up as untracked to git.
Question: I guess I can add these files specifically to .gitignore, but can i force them to be generated in the .vercel/output directory?
My main objective is to keep the GitLab repo clean.
and many thanks for the recent help.

1 Like

@band101 Yes, you can keep your GitLab repo clean by managing build artifacts. Here’s how:

  1. Use the .vercel/output directory for build artifacts:
 #!/bin/bash#!/bin/bash
mkdir -p .vercel/output/static
cd .vercel/output/static
# Run your build commands here

  1. For files like package.json and lock files that appear after the build:
  • Add them to .gitignore, or
  • Clean them up in your build.sh:
 # At the end of build.sh# At the end of build.sh
rm -f package.json package-lock.json

The .vercel directory is automatically ignored by Git, so artifacts generated there won’t show as untracked files.

Let us know how you get on!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.