No home isolation with apptainer can cause Python errors when running heudiconv #1

Closed
opened 2025-09-09 12:37:44 +00:00 by msz · 0 comments
Member

Running with apptainer according to the instructions means that home directory is mounted (default apptainer behavior), which can cause Python errors (depending on ~/local/lib contents) unless the environment variable APPTAINER_NO_HOME=1 is set.

Detailed explanation:

I am running a command which is equivalent to the instructions provided in the README, with small changes which are not relevant for this issue (no mapping of identifiers, heuristic is not annexed, the input file is a tarball, long options are used):

❱ datalad containers-run \
  -m "Convert phantom data" \
  -n code/heudiconv/apptainer \
  -o sub-Ph020925 -o .heudiconv/sub-Ph020925 \
  -i sourcedata/Ph020925_Q01Aachen.tgz \
  -- \
  --bids notop --overwrite --minmeta \
  --outdir . \
  --heuristic code/heuristic-q01.py \
  --subjects Ph020925 \
  --files '{inputs[0]}'

I get errors which originate with my ~/.local/lib/python3.9/site-packages:

Traceback (most recent call last):
  File "/opt/miniconda-py39_4.12.0/bin/heudiconv", line 5, in <module>
    from heudiconv.cli.run import main
  File "/src/heudiconv/heudiconv/cli/run.py", line 11, in <module>
    from ..main import workflow
  File "/src/heudiconv/heudiconv/main.py", line 11, in <module>
    from .bids import populate_bids_templates, populate_intended_for, tuneup_bids_json_files
  File "/src/heudiconv/heudiconv/bids.py", line 23, in <module>
    from . import __version__, dicoms
  File "/src/heudiconv/heudiconv/dicoms.py", line 48, in <module>
    import nibabel.nicom.dicomwrappers as dw
  File "/home/mszczepanik/.local/lib/python3.9/site-packages/nibabel/__init__.py", line 40, in <module>
    from . import analyze as ana
  File "/home/mszczepanik/.local/lib/python3.9/site-packages/nibabel/analyze.py", line 87, in <module>
    from .volumeutils import (native_code, swapped_code, make_dt_codes,
  File "/home/mszczepanik/.local/lib/python3.9/site-packages/nibabel/volumeutils.py", line 21, in <module>
    from .casting import (shared_range, type_info, OK_FLOATS)
  File "/home/mszczepanik/.local/lib/python3.9/site-packages/nibabel/casting.py", line 713, in <module>
    OK_FLOATS = ok_floats()
  File "/home/mszczepanik/.local/lib/python3.9/site-packages/nibabel/casting.py", line 707, in ok_floats
    floats = np.sctypes['float'][:]
  File "/opt/miniconda-py39_4.12.0/lib/python3.9/site-packages/numpy/__init__.py", line 397, in __getattr__
    raise AttributeError(
AttributeError: `np.sctypes` was removed in the NumPy 2.0 release. Access dtypes explicitly instead.

When I first export APPTAINER_NO_HOME=1, everything proceeds smoothly.

FWIW, repronim-containers does some adaptations of binds, environment, etc for the singularity command (221 line bash wrapper).

The error is clearly dependent on my specific environment (Python 3.9 leftovers I would say) but perhaps we should suggest some isolation settings in the README or include them in the apptainer command in datalad-containers configuration? I think --no-home is sufficient but also consider --containall (see Bind paths and mounts and --cleanenv.

Running with apptainer according to the instructions means that home directory is mounted (default apptainer behavior), which can cause Python errors (depending on `~/local/lib` contents) unless the environment variable `APPTAINER_NO_HOME=1` is set. Detailed explanation: I am running a command which is equivalent to the instructions provided in the README, with small changes which are not relevant for this issue (no mapping of identifiers, heuristic is not annexed, the input file is a tarball, long options are used): ``` ❱ datalad containers-run \ -m "Convert phantom data" \ -n code/heudiconv/apptainer \ -o sub-Ph020925 -o .heudiconv/sub-Ph020925 \ -i sourcedata/Ph020925_Q01Aachen.tgz \ -- \ --bids notop --overwrite --minmeta \ --outdir . \ --heuristic code/heuristic-q01.py \ --subjects Ph020925 \ --files '{inputs[0]}' ``` I get errors which originate with my `~/.local/lib/python3.9/site-packages`: ``` Traceback (most recent call last): File "/opt/miniconda-py39_4.12.0/bin/heudiconv", line 5, in <module> from heudiconv.cli.run import main File "/src/heudiconv/heudiconv/cli/run.py", line 11, in <module> from ..main import workflow File "/src/heudiconv/heudiconv/main.py", line 11, in <module> from .bids import populate_bids_templates, populate_intended_for, tuneup_bids_json_files File "/src/heudiconv/heudiconv/bids.py", line 23, in <module> from . import __version__, dicoms File "/src/heudiconv/heudiconv/dicoms.py", line 48, in <module> import nibabel.nicom.dicomwrappers as dw File "/home/mszczepanik/.local/lib/python3.9/site-packages/nibabel/__init__.py", line 40, in <module> from . import analyze as ana File "/home/mszczepanik/.local/lib/python3.9/site-packages/nibabel/analyze.py", line 87, in <module> from .volumeutils import (native_code, swapped_code, make_dt_codes, File "/home/mszczepanik/.local/lib/python3.9/site-packages/nibabel/volumeutils.py", line 21, in <module> from .casting import (shared_range, type_info, OK_FLOATS) File "/home/mszczepanik/.local/lib/python3.9/site-packages/nibabel/casting.py", line 713, in <module> OK_FLOATS = ok_floats() File "/home/mszczepanik/.local/lib/python3.9/site-packages/nibabel/casting.py", line 707, in ok_floats floats = np.sctypes['float'][:] File "/opt/miniconda-py39_4.12.0/lib/python3.9/site-packages/numpy/__init__.py", line 397, in __getattr__ raise AttributeError( AttributeError: `np.sctypes` was removed in the NumPy 2.0 release. Access dtypes explicitly instead. ``` When I first `export APPTAINER_NO_HOME=1`, everything proceeds smoothly. FWIW, repronim-containers does some adaptations of binds, environment, etc for the singularity command ([221 line bash wrapper](https://github.com/ReproNim/containers/blob/master/scripts/singularity_cmd)). The error is clearly dependent on my specific environment (Python 3.9 leftovers I would say) but perhaps we should suggest some isolation settings in the README or include them in the apptainer command in datalad-containers configuration? I think `--no-home` is sufficient but also consider `--containall` (see [Bind paths and mounts](https://apptainer.org/docs/user/main/bind_paths_and_mounts.html) and `--cleanenv`.
mih closed this issue 2025-09-09 17:39:05 +00:00
Sign in to join this conversation.
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
q02/heudiconv-container#1
No description provided.