UniDep

raw JSON →
3.1.0 verified Fri May 01 auth: no python

UniDep unifies Conda and Pip requirements management by parsing a single requirements.yaml file to generate conda environment.yml, pip requirements.txt, pixi.toml, and setuptools dynamic dependencies. Current version: 3.1.0. Release cadence: regular minor releases following semantic versioning.

pip install unidep
error ModuleNotFoundError: No module named 'unidep'
cause UniDep is not installed.
fix
Run pip install unidep to install the package.
error KeyError: 'dependencies'
cause The requirements.yaml file is missing the top-level 'dependencies' key.
fix
Ensure your YAML file starts with dependencies: followed by the list of dependencies.
error yaml.scanner.ScannerError: mapping values are not allowed here
cause Invalid YAML syntax, often due to trailing colons or incorrect indentation.
fix
Validate your YAML file with a YAML linter; ensure proper indentation and format per the UniDep spec.
breaking In version 2.0.0, the `local_dependencies` field schema changed to support a dictionary format. v1.x cannot read v2.0.0 files using the new format.
fix Upgrade configuration if using new dictionary format, but note that v1.x consumers will break.
gotcha The `unidep` command-line interface writes files in the current directory by default. Always verify your working directory to avoid overwriting existing files.
fix Use `--output-dir` flag to specify a safe output directory.
gotcha When using pip-only packages in a conda environment, UniDep may demote them to pip dependencies. This can cause runtime import errors if the package is unavailable via conda.
fix Explicitly list the package in both conda and pip sections if you need conda to install it; use `conda:` and `pip:` keys precisely.

Parse a requirements.yaml file and output a conda environment.yml dict.

from unidep import UniDep
import os

# Create a simple requirements.yaml content as string
req_yaml = """
# requirements.yaml
dependencies:
  - python >=3.9
  - pip
  - pip:
    - requests
"""
import tempfile
with tempfile.NamedTemporaryFile(mode='w', suffix='.yaml', delete=False) as f:
    f.write(req_yaml)
    req_file = f.name

# Parse and generate conda environment.yml
ud = UniDep(req_file)
env = ud.to_conda_env()
print(env)
os.unlink(req_file)