LinuxCommandLibrary

conda-package

Create conda packages

TLDR

Get conda package from file

$ conda package [[-w|--which]] [path/to/file]
copy

Remove all untracked files
$ conda package [[-r|--reset]]
copy

Display all untracked files
$ conda package [[-u|--untracked]]
copy

Designate package name of the package being created
$ conda package --pkg-name [name]
copy

Designate package version of the package being created
$ conda package --pkg-version [version]
copy

Designate package build number of the package being created
$ conda package --pkg-build [build_number]
copy

SYNOPSIS

conda-package [OPTIONS] [PREFIX]

PARAMETERS

-o, --output FILE
    Specify output archive filename. Default: <env>.tar.gz in current directory.

-n, --name NAME
    Name of the environment to package.

-p, --prefix PREFIX
    Full path to the environment prefix. Mutually exclusive with --name.

--arch ARCH
    Override detected architecture (e.g., linux-64).

--platform PLATFORM
    Override detected platform (e.g., linux-64).

--force
    Overwrite existing output file if present.

--ignore-missing-files
    Continue packing even if files are missing.

--zstd
    Use zstd compression for the archive.

--zstd-compression-level LEVEL
    Zstd compression level (1-22). Default: 1.

--relocate-prefix PREFIX
    Set relocation prefix for post-unpack adjustment.

--dry-run
    Show what would be packed without creating archive.

-v, --verbose
    Enable verbose output.

-q, --quiet
    Suppress non-error output.

--help
    Show help message and exit.

--version
    Show version and exit.

DESCRIPTION

conda-package is a utility designed to create self-contained, relocatable archives of conda environments. It bundles all binaries, libraries, and metadata into a single tarball (typically .tar.gz), allowing deployment to other machines without requiring conda or internet access on the target system.

This tool is essential for scenarios like containerization, HPC clusters, air-gapped networks, or server deployments where environment reproducibility is critical. During packing, it rewrites shebang lines in scripts to reference the bundled Python interpreter, adjusts RPATHs in binaries for library locations, preserves symlinks and hardlinks, and handles platform-specific details.

To use, activate the target environment and run conda-package, producing an archive like myenv.tar.gz. On the destination, extract with tar -xzf myenv.tar.gz -C /target/path. The environment is then ready; activate via source /target/path/bin/activate. Supports compression options like gzip, bzip2, and zstd for balancing size and speed.

While powerful, success depends on package compatibility—pure Python works perfectly, but some native extensions may need rebuilding if paths or ABIs differ.

CAVEATS

Requires matching OS/architecture/libc on target; not all packages (e.g., with hardcoded paths) relocate perfectly. Test thoroughly. Large environments produce big archives. Activate env before packing for best results.

INSTALLATION

conda install -c conda-forge conda-pack or pip install conda-pack.

UNPACKING

Extract with tar -xzf env.tar.gz -C /new/path, then source /new/path/bin/activate.

COMMON USE

Pack active env: conda-package -o myenv.tar.gz.

HISTORY

Originally developed as conda-pack by the conda-forge community around 2018 to solve relocatable env needs in HPC and deployments. Evolved with zstd support and better relocation in recent versions (maintained on GitHub/conda-forge).

SEE ALSO

conda(1), tar(1), mamba(1), micromamba(1)

Copied to clipboard