anomalyco/sst · error

failed to generate requirements file: %w

Error message

failed to generate requirements file: %w

What it means

After creating the output directory, installDependenciesForBuild produces requirements.txt in it via generateOrCopyRequirementsFile (generated once per workspace from the project's Python package config, or copied from source). Failure here means no requirements file could be produced, so dependency installation cannot proceed.

Source

Thrown at pkg/runtime/python/build.go:554

		if err := copyFile(srcFile, destFile); err != nil {
			return fmt.Errorf("failed to copy %s to %s: %w", srcFile, destFile, err)
		}
	}

	// Clean up the extracted directory
	os.RemoveAll(extractedDir)

	return nil
}

func installDependenciesForBuild(ctx context.Context, input *runtime.BuildInput, projectInfo *projectInfo) error {
	if err := os.MkdirAll(input.Out(), 0755); err != nil {
		return fmt.Errorf("failed to create output directory: %w", err)
	}

	requirementsFile := filepath.Join(input.Out(), "requirements.txt")
	if err := generateOrCopyRequirementsFile(ctx, projectInfo, requirementsFile); err != nil {
		return fmt.Errorf("failed to generate requirements file: %w", err)
	}

	// Determine architecture for Lambda
	architecture := "x86_64"
	if props, err := parseInputProperties(input); err == nil && props.Architecture != "" {
		architecture = props.Architecture
	}

	// Install dependencies for the target platform (Linux)
	if err := installDependenciesForLambda(ctx, input, projectInfo, architecture); err != nil {
		return fmt.Errorf("failed to install dependencies: %w", err)
	}

	return nil
}

// generateOrCopyRequirementsFile generates requirements.txt once per workspace,
// then copies it to each function's output directory.

View on GitHub (pinned to a0bd20f762)

Solutions

  1. Check the requirements.txt / pyproject.toml exists at the configured source path and is readable; restore it (git checkout -- path/to/requirements.txt)
  2. Validate the pyproject.toml syntax (tomllib parse or `pip install -e .` locally) if the file is generated from it
  3. Fix write permissions on the build output directory
  4. Verify your sst config's srcPath/path points at the directory that actually contains the dependency manifest

Example fix

// before (missing requirements.txt)
$ rm requirements.txt && go run ../../cmd/sst deploy
// error: failed to generate requirements file
// after
$ git checkout -- requirements.txt   # or create one:
$ printf 'requests==2.32.3\n' > requirements.txt
Defensive patterns

Strategy: validation

Validate before calling

req := filepath.Join(srcPath, "requirements.txt")
if _, err := os.Stat(req); err != nil {
	log.Fatalf("missing %s — create it or set the correct srcPath", req)
}
if _, err := os.Stat(filepath.Join(srcPath, "pyproject.toml")); err == nil {
	// ensure generator can parse it
	if _, err := os.ReadFile(filepath.Join(srcPath, "pyproject.toml")); err != nil {
		log.Fatalf("pyproject.toml unreadable: %v", err)
	}
}

Try / catch

if err := deploy(); err != nil && strings.Contains(err.Error(), "failed to generate requirements file") {
	fmt.Println("check requirements.txt / pyproject.toml in your srcPath exists, is readable, and is valid")
	os.Exit(1)
}

Prevention

When it happens

Trigger: generateOrCopyRequirementsFile fails: the source requirements.txt/pyproject.toml it reads is missing, unreadable, or invalid; writing the generated file to input.Out() fails (permissions/disk); workspace root resolution returns an empty/wrong path.

Common situations: PythonFunction configured with a path whose requirements.txt was deleted or renamed; pyproject.toml with malformed TOML the generator can't parse; read-only build output dir; monorepo layout where the workspace root was moved.

Related errors


AI-assisted analysis of anomalyco/sst@a0bd20f762 (2026-08-30). Data as JSON: /api/errors/828db8aab3305510. Report an issue: GitHub.