ANTs not being found by `nipype`

Hi,
I am being unable to make the nipype ANTs interface work in my project (nifreeze). I have nipype 1.9.2 installed and when running the following nifreeze notebook,
nifreeze/docs/notebooks/pet_motion_estimation.ipynb at main · nipreps/nifreeze · GitHub

it complains because it is unable to find ANTs:

Failed to process frame 1 due to No command "antsRegistration" found on host muswachasut. Please check that the corresponding package is installed.

ANTs is in my PATH and I can use it without issues from the command line, e.g.:

$ which antsRegistration
/opt/ants/ants-2-5-1/bin/antsRegistration

I have tried adding /opt/ants/ants-2-5-1/bin/ explicitly to the notebook environment variable settings without success. Have also tried the below simple snippet in a Python script, adding ANTs explicitly to the environment variables, and I get the same error.

from pathlib import Path
from nipype.interfaces.ants.registration import Registration

tmp_path = Path("/path/to/random/nifti/files")
fixed_image_path = tmp_path / f"fixed_frame_000.nii.gz"
moving_image_path = tmp_path / f"moving_frame_000.nii.gz"

registration_config = Path("/path/to/nifreeze/registration/config/pet-to-pet_level1.json")

registration = Registration(
    from_file=registration_config,
    fixed_image=str(fixed_image_path),
    moving_image=str(moving_image_path),
    output_warped_image=True,
    output_transform_prefix=f"ants_000",
)

result = registration.run(cwd=str(tmp_path))

What am I missing?

I am running this on an Ubuntu 22.04. I had not used conda to install ANTs (think installed through apt-get, i.e. sudo apt-get install ants). nipype was installed through the project’s dependencies in pyproject.toml.

Have seem similar questions being asked in the nipype GitHub issues; unfortunately, the exchanges have not ended up in suggestions that have fixed them.

Thanks.

Hi @jhlegarreta,

What if you add ants to your path in the python script with sys.path.append?

Best,
Steven

Results in the same error.

Hi @jhlegarreta,

What about

os.environ["PATH"] += os.pathsep + “/opt/ants/ants-2-5-1/bin/“

Best,
Steven

That worked. Looks like my IDE (PyCharm) is not doing a good job taking the values on my PATH variable: printing its contents does not show the same values I get when doing an echo $PATH in the terminal. The script works if I try running the script from the command line without the mentioned statement. I have not figured out how to make PyCharm take my PATH values properly, but at least I can now run the notebook/script adding the above statement manually. Thanks @Steven :100:.

1 Like