Skip to content

Create a Conda environment file from a Python project using uv.

License

Notifications You must be signed in to change notification settings

fepegar/uv2conda

Repository files navigation

uv2conda

uv PyPI

Tiny Python package to create a conda environment file from a Python project using uv.

Assuming you have installed uv:

uvx uv2conda \
    --project-dir "/path/to/my/project/" \
    --name "my_conda_env_name" \
    --python "3.12.7" \
    --conda-env-file "my_conda_env.yaml" \
    --requirements-file "requirements.txt" \
    -- \
        --prerelease=allow

Or, in Python:

from uv2conda import CondaEnvironment

environment = CondaEnvironment.from_project_dir(
    project_dir="/path/to/my/project/",
    name="my_conda_env_name",
    python_version="3.12.7",
    uv_args=["--prerelease=allow"],
)
environment.to_pip_requirements_file("requirements.txt")
environment.to_yaml("environment.yaml")

Example for this library:

$ uv2conda --python 3.12.7
[23:17:34] WARNING  Environment name not provided. Using project directory name ("uv2conda")
           INFO     Printing the generated conda environment YAML
name: uv2conda
dependencies:
  - python=3.12.7
  - pip
  - pip:
      - click==8.1.7
      - colorama==0.4.6 ; sys_platform == 'win32'
      - markdown-it-py==3.0.0
      - mdurl==0.1.2
      - packaging==24.2
      - pygments==2.18.0
      - pyyaml==6.0.2
      - rich==13.9.4
      - shellingham==1.5.4
      - typer==0.15.1
      - typing-extensions==4.12.2

Using uv2conda with pre-commit

To ensure your Conda environment YAML is up-to-date with your uv.lock, your uv lock file:

- repo: https://github.com/fepegar/uv2conda
  rev: v1.0.1
  hooks:
    - id: uv2conda

Related projects

About

Create a Conda environment file from a Python project using uv.

Resources

License

Stars

Watchers

Forks