Unable to use ITK filters when packaging my Python project that lists ITK as a requirement.

Hello,

I am relatively new to Python and I have a Python project with a requirements.txt file and a setup.py file inside of it. My requirements.txt file has itk listed as a requirement. The code in my setup.py file reads the requirements.txt file and sets the install_requires variable with the list of requirements.

When I create a new Anaconda virtual environment and run setup.py install, it installs all the requirements for my project, including itk-meshtopolydata, itk-filtering, itk-core, itk-io, itk-segmentation, itk-registration, and itk-numerics (I assume it got those from the itk requirement).

However, when I try to use ITK’s IntensityWindowingImageFilter in my Python code with the code itk.IntensityWindowingImageFilter[img_type, img_type].New(), an error appears and tells me module 'itk' has no attribute 'IntensityWindowingImageFilter'

I re-ran python setup.py install and this is some of the ITK-related output that I got:

Searching for itk-meshtopolydata==0.6.5
Best match: itk-meshtopolydata 0.6.5
Processing itk_meshtopolydata-0.6.5-py3.8-macosx-10.9-x86_64.egg
itk-meshtopolydata 0.6.5 is already the active version in easy-install.pth

Using /Users/joeykleingers/.conda/envs/testenv/lib/python3.8/site-packages/itk_meshtopolydata-0.6.5-py3.8-macosx-10.9-x86_64.egg
Searching for itk-filtering==5.2rc3
Best match: itk-filtering 5.2rc3
Processing itk_filtering-5.2rc3-py3.8-macosx-10.9-x86_64.egg
itk-filtering 5.2rc3 is already the active version in easy-install.pth

Using /Users/joeykleingers/.conda/envs/testenv/lib/python3.8/site-packages/itk_filtering-5.2rc3-py3.8-macosx-10.9-x86_64.egg
Searching for itk-core==5.2rc3
Best match: itk-core 5.2rc3
Processing itk_core-5.2rc3-py3.8-macosx-10.9-x86_64.egg
itk-core 5.2rc3 is already the active version in easy-install.pth

Using /Users/joeykleingers/.conda/envs/testenv/lib/python3.8/site-packages/itk_core-5.2rc3-py3.8-macosx-10.9-x86_64.egg
Searching for ipywidgets==8.0.0a4
Best match: ipywidgets 8.0.0a4
Processing ipywidgets-8.0.0a4-py3.8.egg
ipywidgets 8.0.0a4 is already the active version in easy-install.pth

Using /Users/joeykleingers/.conda/envs/testenv/lib/python3.8/site-packages/ipywidgets-8.0.0a4-py3.8.egg
Searching for ipympl==0.7.0
Best match: ipympl 0.7.0
Processing ipympl-0.7.0-py3.8.egg
ipympl 0.7.0 is already the active version in easy-install.pth

Using /Users/joeykleingers/.conda/envs/testenv/lib/python3.8/site-packages/ipympl-0.7.0-py3.8.egg
Searching for ipydatawidgets==4.2.0
Best match: ipydatawidgets 4.2.0
Processing ipydatawidgets-4.2.0-py3.8.egg
ipydatawidgets 4.2.0 is already the active version in easy-install.pth

Using /Users/joeykleingers/.conda/envs/testenv/lib/python3.8/site-packages/ipydatawidgets-4.2.0-py3.8.egg
Searching for itk-io==5.2rc3
Best match: itk-io 5.2rc3
Processing itk_io-5.2rc3-py3.8-macosx-10.9-x86_64.egg
itk-io 5.2rc3 is already the active version in easy-install.pth

Using /Users/joeykleingers/.conda/envs/testenv/lib/python3.8/site-packages/itk_io-5.2rc3-py3.8-macosx-10.9-x86_64.egg
Searching for itk-segmentation==5.2rc3
Best match: itk-segmentation 5.2rc3
Processing itk_segmentation-5.2rc3-py3.8-macosx-10.9-x86_64.egg
itk-segmentation 5.2rc3 is already the active version in easy-install.pth

Using /Users/joeykleingers/.conda/envs/testenv/lib/python3.8/site-packages/itk_segmentation-5.2rc3-py3.8-macosx-10.9-x86_64.egg
Searching for itk-registration==5.2rc3
Best match: itk-registration 5.2rc3
Processing itk_registration-5.2rc3-py3.8-macosx-10.9-x86_64.egg
itk-registration 5.2rc3 is already the active version in easy-install.pth

Using /Users/joeykleingers/.conda/envs/testenv/lib/python3.8/site-packages/itk_registration-5.2rc3-py3.8-macosx-10.9-x86_64.egg
Searching for itk-numerics==5.2rc3
Best match: itk-numerics 5.2rc3
Processing itk_numerics-5.2rc3-py3.8-macosx-10.9-x86_64.egg
itk-numerics 5.2rc3 is already the active version in easy-install.pth

Using /Users/joeykleingers/.conda/envs/testenv/lib/python3.8/site-packages/itk_numerics-5.2rc3-py3.8-macosx-10.9-x86_64.egg

For reference, here is my setup.py file:

from setuptools import setup, find_packages

with open('README.md', 'r') as file:
  long_description = file.read()

install_requires = []
with open('requirements.txt') as file:
  install_requires = [line for line in file.read().splitlines() if len(line) > 0]

setup(
  name='ifam',
  version='0.1.0',
  long_description=long_description,
  long_description_content_type='text/markdown',
  packages=find_packages(),
  license='BSD',
  platforms='any',
  classifiers=[
      'Programming Language :: Python :: 3',
      'License :: OSI Approved :: BSD License'
  ],
  python_requires='>=3.8',
  install_requires=install_requires
)

And my requirements.txt file:

numpy
dask-image
dask-labextension
dask-mpi
dask
zarr
xarray
itk
itk-thickness3d
itk-montage
itkwidgets
aicspylibczi
Pillow
pathlib
tqdm

Am I doing the packaging wrong? How do I set up the packaging properly to be able to use ITK filters?

UPDATE: I created a brand new virtual environment and ran the pip install . command instead of python setup.py install and now it works. Not really sure why this works and the other doesn’t, but at least it works now.

2 Likes