0

I have the following code:

import sys
import os
import numpy
import pathlib
from ants import image_read, resample_image, iMath, from_numpy, threshold_image, copy_image_info, image_write
from copy import copy
from keras.models import load_model
from keras import backend as K
import timeit

On line 5, I get an error: ImportError: cannot import name 'image_read' from 'ants'. Why does this occur? How can I fix the ImportError?

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
WSchalls
  • 17
  • 2
  • Did you install the package `ANTsPy` using `pip install antspyx` in your project environment? – crock Jun 16 '22 at 19:44
  • Yes, I did. So I am unsure why it is causing me this issue – WSchalls Jun 16 '22 at 19:46
  • 3
    Show the full traceback. Do you have a local file called `ants.py` lying around? – wim Jun 16 '22 at 20:11
  • Welcome to Stack Overflow. Did you try [reading the documentation](https://antspyx.readthedocs.io/en/latest/?badge=latest)? In your own words, why do you expect `from ants import image_read` to work? I mean - why should there be an `image_read` contained in `ants` - according to what source? If you saw some existing code that uses this library, did you try to check how *that* code gets access to `image_read`? – Karl Knechtel Jun 16 '22 at 20:11
  • 2
    "Does anyone know a good solution for this problem? All suggestions are appreciated and helpful!" Please read [ask] and note that this is **not a discussion forum**. We are looking for a *specific question*; a call for suggestions [does not qualify](https://meta.stackoverflow.com/questions/284236). Better: "Why do I get this error, and how can I fix it?" – Karl Knechtel Jun 16 '22 at 20:12

0 Answers0