astral-sh/uv · error · anyhow::Error

File not found: `{}`

Error message

File not found: `{}`

What it means

Thrown in RequirementsSpecification::from_source_with_cache (crates/uv-requirements/src/specification.rs:276) when a RequirementsTxt source path is not an http:// or https:// URL and does not exist on disk. uv checks existence before attempting to parse so the user gets a clear message instead of a raw io::Error from the parser.

Source

Thrown at crates/uv-requirements/src/specification.rs:276

            RequirementsSource::Package(requirement) => Self {
                requirements: vec![UnresolvedRequirementSpecification::from(
                    requirement.clone(),
                )],
                ..Self::default()
            },
            RequirementsSource::Editable(requirement) => {
                let mut requirement = requirement.clone();
                requirement.make_editable().with_context(|| {
                    format!("Unsupported editable requirement: `{requirement}`")
                })?;
                Self {
                    requirements: vec![UnresolvedRequirementSpecification::from(requirement)],
                    ..Self::default()
                }
            }
            RequirementsSource::RequirementsTxt(path) => {
                if !(path.starts_with("http://") || path.starts_with("https://") || path.exists()) {
                    return Err(anyhow::anyhow!("File not found: `{}`", path.user_display()));
                }

                let requirements_txt =
                    RequirementsTxt::parse_with_cache(path, &*CWD, client_builder, cache).await?;

                if requirements_txt == RequirementsTxt::default() {
                    warn_user!(
                        "Requirements file `{}` does not contain any dependencies",
                        path.user_display()
                    );
                }

                Self::from_requirements_txt(requirements_txt)
            }
            RequirementsSource::PyprojectToml(path) => {
                let content = match fs_err::tokio::read_to_string(&path).await {
                    Ok(content) => content,
                    Err(err) if err.kind() == std::io::ErrorKind::NotFound => {

View on GitHub (pinned to f1a42680ff)

Solutions

  1. Verify the file exists at the path uv resolved: `ls` the exact relative path from your current directory
  2. Run uv from the directory containing the file, or use an absolute path
  3. If the file is remote, pass a full http(s):// URL (those bypass the existence check)

Example fix

# before (run from repo root, file lives in deploy/)
uv pip install -r requirements.txt
# after
uv pip install -r deploy/requirements.txt
Defensive patterns

Strategy: validation

Validate before calling

fn requirements_source_usable(path: &Path) -> bool {
    let s = path.to_string_lossy();
    s.starts_with("http://") || s.starts_with("https://") || path.exists()
}

if !requirements_source_usable(&path) {
    return Err(anyhow::anyhow!("File not found: `{}`", path.display()));
}

Try / catch

match RequirementsSpecification::from_source(source, &client_builder).await {
    Err(err) if err.to_string().starts_with("File not found:") => {
        // resolve/locate the file, prompt the user, or skip
    }
    spec => spec?,
}

Prevention

When it happens

Trigger: `uv pip install -r missing.txt`, `uv pip compile -r reqs/prod.txt` from the wrong working directory, or programmatically building a RequirementsSource::RequirementsTxt for a path that was deleted or never created; note `-r -` (stdin) becomes an Extensionless source and never hits this.

Common situations: Running uv from a different cwd than assumed (paths are resolved relative to the invocation directory, not the pyproject); CI checkout missing a generated requirements file; typos or stale paths in scripts; a file present locally but absent in Docker build context.

Related errors


AI-assisted analysis of astral-sh/uv@f1a42680ff (2026-08-16). Data as JSON: /api/errors/0091d7acaa2d3fad. Report an issue: GitHub.