conda-pack

0.9.1 · active · verified Fri Apr 17

conda-pack is a utility for packaging conda environments, including all their dependencies, into a single relocatable archive (e.g., .tar.gz, .zip, .squashfs). This allows for easy redistribution and deployment of isolated Python environments across different systems. It's currently at version 0.9.1 and is actively maintained with a moderate release cadence, typically a few releases per year.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to pack an existing conda environment into a tar.gz archive using the `conda pack` command-line tool. It first ensures a sample environment exists, then packs it to a specified output file. The `--force` flag overwrites the output if it already exists.

import os
import subprocess

# Create a dummy environment for demonstration if it doesn't exist
env_name = 'my_packed_env'
if subprocess.run(['conda', 'env', 'list'], capture_output=True, text=True).stdout.find(env_name + ' ') == -1:
    print(f"Creating dummy conda environment '{env_name}'...")
    subprocess.run(['conda', 'create', '-n', env_name, 'python=3.9', 'numpy', '-y'], check=True)

output_filename = f'{env_name}.tar.gz'

# Pack the environment using the command line tool
print(f"Packing environment '{env_name}' to '{output_filename}'...")
subprocess.run(['conda', 'pack', '-n', env_name, '-o', output_filename, '--force'], check=True)

print(f"Environment packed to {output_filename}")

# To unpack (demonstrative, not part of conda-pack library itself)
# print(f"Unpacking {output_filename} to ./unpacked_env")
# os.makedirs('./unpacked_env', exist_ok=True)
# subprocess.run(['tar', '-xzf', output_filename, '-C', './unpacked_env'], check=True)

# To use the Python API directly:
# from conda_pack import pack
# pack(name=env_name, output=output_filename, force=True)

view raw JSON →