Skip to main content

Conda+Pip minimal env exports

Project description

conda cpm

Simple tool to generate minimal versions of Conda environments, also including pip dependencies, for cross-platform sharing.

Built on top of conda tree and pipdeptree. Inspired by conda minify.

Why use conda cpm?

  • Conda (especially with mamba) is a great tool to manage Python virtual environments, especially if you need to install some non-Python dependencies, or use compiled dependencies like CUDA. See https://aseifert.com/p/python-environments/ for more on this.

  • I use Conda preferentially to install any packages available through it; and provide my virtualenv’s Python version through Conda.

  • Some packages are not easily accessible on Conda, and I use pip or poetry (or hatch or your other tool of choice) to pull those packages in.

  • This approach works remarkably well, but when it is time to share my environment with others, there are several ways to do it, and they are subtly different in capabilities and issues.

    e.g

    • conda env export, conda env export --from-history, conda list --export

    • For pip-installed packages, pip freeze, pip list --freeze, or whatever your favorite Python package manager provides.

    • conda-lock, pipenv, and other lock file generating tools

  • If the exported file is too specific, specifying every dependency and build identifier, it often cannot be reproduced on a different platform because these are not portable.

  • If you use both conda and pip, these tools will typically be unaware of each other, generating overlapping requirements files.

How does conda cpm solve this?

  • conda cpm constructs a minimal environment.yml file, with only the "leaves" of the dependency tree, both for pip and conda.

  • It retains information about which packages came from Conda and which came from Pip, but does not include dependencies in the export.

  • It specifies exact versions by default, but it can optionally relax the version requirements to being flexible at the patch level or minor level (semver).

  • It can optionally include info about which Conda channel a package came from, the Python version, or any manually specified packages.

  • It does not include system-specific information like the Conda environment prefix.

Installation

via pip

pip install conda-pip-minimal

via pipx

pipx install conda-pip-minimal

Run without installing

pipx run conda-pip-minimal --help

Usage

The script for this package is named conda-cpm; so it can be run like conda cpm

$ conda cpm [OPTIONS]

Options:

  • -p, --prefix PATH: Conda env prefix
  • -n, --name TEXT: Conda env name
  • --pip / --no-pip: Include pip dependencies [default: True]
  • --relax [none|major|minor|full]: [default: full]
  • --include TEXT: Packages to always include [default: python, pip]
  • --exclude TEXT: Packages to always exclude [default: ]
  • --channel / --no-channel: Add channel to conda dependencies [default: False]
  • --debug / --no-debug: [default: False]
  • --help: Show this message and exit.

Examples

Here are a few example runs for this package:

From within the conda environment:

 conda cpm
dependencies:
- python=3.8.13
- pip=22.2.2
- pip:
  - conda-pip-minimal==0.1.0
  - ipython==8.5.0
  - snoop==0.4.2
  - trio-typing==0.7.0
name: /home/venky/dev/conda-pip-minimal/.venv

Specifying the conda environment

 conda cpm --prefix ~/dev/conda-pip-minimal/.venv
dependencies:
- pip=22.2.2
- python=3.8.13
- pip:
  - conda-pip-minimal==0.1.0
  - ipython==8.5.0
  - snoop==0.4.2
  - trio-typing==0.7.0
name: /home/venky/dev/conda-pip-minimal/.venv

Exclude packages

 conda cpm --prefix ~/dev/conda-pip-minimal/.venv --exclude snoop --exclude trio-typing
dependencies:
- python=3.8.13
- pip=22.2.2
- pip:
  - conda-pip-minimal==0.1.0
  - ipython==8.5.0
name: /home/venky/dev/conda-pip-minimal/.venv

Include a normally-excluded dependency

 conda cpm --prefix ~/dev/conda-pip-minimal/.venv --include trio
dependencies:
- trio=0.22.0
- pip:
  - conda-pip-minimal==0.1.0
  - ipython==8.5.0
  - snoop==0.4.2
  - trio-typing==0.7.0
name: /home/venky/dev/conda-pip-minimal/.venv

Specify conda channels

 conda cpm --prefix ~/dev/conda-pip-minimal/.venv --channel
dependencies:
- conda-forge::python=3.8.13
- conda-forge::pip=22.2.2
- pip:
  - conda-pip-minimal==0.1.0
  - ipython==8.5.0
  - snoop==0.4.2
  - trio-typing==0.7.0
name: /home/venky/dev/conda-pip-minimal/.venv

Relax versions

 conda cpm --prefix ~/dev/conda-pip-minimal/.venv --relax minor
dependencies:
- python=3.8.*
- pip=22.2.*
- pip:
  - conda-pip-minimal==0.1.*
  - ipython==8.5.*
  - snoop==0.4.*
  - trio-typing==0.7.*
name: /home/venky/dev/conda-pip-minimal/.venv

Skip pip dependencies

Why would you want to do this, though?

 conda cpm --prefix ~/dev/conda-pip-minimal/.venv --no-pip
dependencies:
- pip=22.2.2
- python=3.8.13
name: /home/venky/dev/conda-pip-minimal/.venv

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

conda_pip_minimal-0.2.1.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

conda_pip_minimal-0.2.1-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file conda_pip_minimal-0.2.1.tar.gz.

File metadata

  • Download URL: conda_pip_minimal-0.2.1.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.23.1

File hashes

Hashes for conda_pip_minimal-0.2.1.tar.gz
Algorithm Hash digest
SHA256 b27138eb96ffa1c57c7d1c2a423b373baaa22e70ce1086fe8538dbe276566867
MD5 e50a59d92ba846edba5257ee6a7dd1ae
BLAKE2b-256 da83b05cf7419bc64d1b199bec5d4e9de0ed6379e5abcaeab3571cebae84ee8d

See more details on using hashes here.

File details

Details for the file conda_pip_minimal-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for conda_pip_minimal-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 618cdfddfcab2f021090e78f7883aba0a2ceeb34561f8288e7a30df38812fe04
MD5 332f6a5480ef104292453afa30013f94
BLAKE2b-256 349c59f06654055541398d467f195c5479ba4b130a9399a10026a5bd2c0819f9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page