Enable pip install by deferring conda-only imports#1213
Conversation
- Move nifty.tools blocking import inside functions that use it - Move vigra import inside get_centers_and_bounding_boxes - Move elf.io open_file import inside load_image_data - Avoids import errors when optional deps not installed Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Move project metadata from setup.cfg into pyproject.toml with pip-installable core deps and optional extras, while lazy-importing nifty, vigra, and python-elf only where needed so headless imports avoid conda-forge packages. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Keep packaging changes minimal for Cell-ACDC integration by declaring pip-only install_requires in setup.cfg instead of duplicating metadata in pyproject.toml. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Hi @keejkrej , thank you for your interest in improving the usability of This has the advantage that all features of In general, contributions to |
|
Thanks! Very interested in your new lib, for now I'll just install from my fork. |
Summary
This PR makes the core micro-sam Python API importable and usable via pip without requiring conda-forge-only packages (
nifty,vigra,python-elf).Changes:
nifty,vigra, andpython-elfto the functions that use theminstall_requirestosetup.cfg(PyPI-available deps only)Relates to #1113.
Motivation
Several dependencies used by micro-sam are only available on conda-forge. Importing
micro_sam.utilcurrently pulls them in at module load time, which breaks pip-only installs — even when the caller only needs the core SAM workflow (load model → compute embeddings → segment from prompts).This matters for:
Why this doesn't affect the core neural network workflow
The SAM inference path (
get_sam_model,precompute_image_embeddings,segment_from_points) depends on torch, segment-anything, and standard pip packages. It does not use nifty, vigra, or python-elf.The deferred packages serve orthogonal infrastructure, not the model itself:
niftyvigramode="v")python-elfNone of these participate in encoder/decoder forward passes. Users on pip who don't need tiling, vigra centroids, or elf I/O can install and run the core workflow without conda. Users who need those features can still
conda install -c conda-forge nifty vigra python-elfas today.Test plan
from micro_sam.util import get_sam_modelsucceeds without nifty/vigra/python-elf installedfrom micro_sam.prompt_based_segmentation import segment_from_pointssucceeds without nifty installedload_image_data(..., key=...)still works when python-elf is installedMade with Cursor