astral-sh/uv · error

Cannot specify paths for groups with a `pylock.toml` file; a

Error message

Cannot specify paths for groups with a `pylock.toml` file; all groups must refer to the `pylock.toml` file

What it means

Thrown in RequirementsSpecification::from_sources (crates/uv-requirements/src/specification.rs:494) when requirements include a pylock.toml and a dependency-group entry carries a path. With a lock file, groups must resolve inside the lock itself (dependency-groups are encoded in pylock.toml), so `--group name@path`-style selections pointing at another file are rejected; path-less group names are collected and attached to the lock instead.

Source

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

            }
            if !constraints.is_empty() {
                return Err(anyhow::anyhow!(
                    "Cannot specify constraints with a `pylock.toml` file"
                ));
            }
            if !overrides.is_empty() {
                return Err(anyhow::anyhow!(
                    "Cannot specify overrides with a `pylock.toml` file"
                ));
            }

            // If we have a `pylock.toml`, disallow specifying paths for groups; instead, require
            // that all groups refer to the `pylock.toml` file.
            if let Some(groups) = groups {
                let mut names = Vec::new();
                for group in &groups.groups {
                    if group.path.is_some() {
                        return Err(anyhow::anyhow!(
                            "Cannot specify paths for groups with a `pylock.toml` file; all groups must refer to the `pylock.toml` file"
                        ));
                    }
                    names.push(group.name.clone());
                }

                if !names.is_empty() {
                    spec.groups.insert(
                        pylock_toml.clone(),
                        DependencyGroups::from_args(
                            None,
                            Vec::new(),
                            Vec::new(),
                            false,
                            names,
                            false,
                        ),
                    );

View on GitHub (pinned to f1a42680ff)

Solutions

  1. Drop the path from the group selection: `--group dev` alone, letting it resolve against the pylock.toml's embedded groups
  2. Ensure the lock actually contains the group (regenerate pylock.toml from a project whose pyproject.toml declares the dependency-group)
  3. If you need groups from another file, install from that pyproject.toml instead of the lock

Example fix

# before
uv pip install -r pylock.toml --group dev@../pyproject.toml
# after
uv pip install -r pylock.toml --group dev
Defensive patterns

Strategy: validation

Validate before calling

let has_pylock = requirements.iter().any(|s| matches!(s, RequirementsSource::PylockToml(_)));
if has_pylock {
    if let Some(groups) = &groups {
        if groups.groups.iter().any(|g| g.path.is_some()) {
            return Err(anyhow::anyhow!("group paths are not allowed with pylock.toml; use bare group names"));
        }
    }
}

Try / catch

match RequirementsSpecification::from_sources(/* .. */, groups, /* .. */).await {
    Err(err) if err.to_string().contains("Cannot specify paths for groups") => {
        // strip group paths (keep names) and reassemble
    }
    spec => spec?,
}

Prevention

When it happens

Trigger: `uv pip install -r pylock.toml --group 'dev@./pyproject.toml'` (any group selection whose path is Some) while a pylock.toml is the requirement source; also `--all-extras`/group flows that carry paths in other uv commands reaching this constructor.

Common situations: Monorepo scripts that enable groups from sibling pyproject.toml files reused against a lock install; users assuming group paths still work after adopting pylock.toml.

Related errors


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