Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

After pip install: ImportError: DLL load failed while importing _ITKCommonPython #154

Closed
N-Dekker opened this issue Jun 21, 2022 · 6 comments

Comments

@N-Dekker
Copy link
Collaborator

Could you please help us out? We (@ViktorvdValk @ntatsisk, me) tried to pip install itk-elastix on Windows. It did work well with itk-elastix 0.12.0, but no longer with the latest version, 0.14.1 or 0.14.0. It might be a Windows issue...? See output from the Python terminal, below.

Python 3.9.12 (main, Apr  4 2022, 05:22:27) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import itk
>>> itk.elastix_registration_method
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\ProgramData\Anaconda3\envs\ITKElastixPy39_14\lib\site-packages\itk\support\lazy.py", line 138, in __getattribute__
    base.itk_load_swig_module(module, namespace)
  File "C:\ProgramData\Anaconda3\envs\ITKElastixPy39_14\lib\site-packages\itk\support\base.py", line 96, in itk_load_swig_module
    itk_load_swig_module(dep, namespace)
  File "C:\ProgramData\Anaconda3\envs\ITKElastixPy39_14\lib\site-packages\itk\support\base.py", line 96, in itk_load_swig_module
    itk_load_swig_module(dep, namespace)
  File "C:\ProgramData\Anaconda3\envs\ITKElastixPy39_14\lib\site-packages\itk\support\base.py", line 96, in itk_load_swig_module
    itk_load_swig_module(dep, namespace)
  File "C:\ProgramData\Anaconda3\envs\ITKElastixPy39_14\lib\site-packages\itk\support\base.py", line 132, in itk_load_swig_module
    l_module = loader.load(swig_module_name)
  File "C:\ProgramData\Anaconda3\envs\ITKElastixPy39_14\lib\site-packages\itk\support\base.py", line 291, in load
    l_spec.loader.exec_module(l_module)  # pytype: disable=attribute-error
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "C:\ProgramData\Anaconda3\envs\ITKElastixPy39_14\lib\site-packages\itk\support\..\ITKCommonPython.py", line 13, in <module>
    from . import _ITKCommonPython
ImportError: DLL load failed while importing _ITKCommonPython: The specified module could not be found.
>>> itk.elastix_registration_method
@dzenanz
Copy link
Member

dzenanz commented Jun 28, 2022

I cannot reproduce this:

C:\a>python -m venv pyE

C:\a>pye\Scripts\activate

(pyE) C:\a>pip install --pre itk-elastix
Collecting itk-elastix
  Downloading itk_elastix-0.14.1-cp39-cp39-win_amd64.whl (119.2 MB)
     |████████████████████████████████| 119.2 MB 3.3 MB/s
Collecting itk>=5.3rc4
  Using cached itk-5.3rc4-cp39-cp39-win_amd64.whl (8.3 kB)
Collecting itk-filtering==5.3rc4
  Using cached itk_filtering-5.3rc4-cp39-cp39-win_amd64.whl (24.0 MB)
Collecting itk-numerics==5.3rc4
  Using cached itk_numerics-5.3rc4-cp39-cp39-win_amd64.whl (20.2 MB)
Collecting itk-core==5.3rc4
  Using cached itk_core-5.3rc4-cp39-cp39-win_amd64.whl (36.1 MB)
Collecting numpy
  Downloading numpy-1.23.0-cp39-cp39-win_amd64.whl (14.7 MB)
     |████████████████████████████████| 14.7 MB 3.3 MB/s
Collecting itk-registration==5.3rc4
  Using cached itk_registration-5.3rc4-cp39-cp39-win_amd64.whl (9.1 MB)
Collecting itk-segmentation==5.3rc4
  Using cached itk_segmentation-5.3rc4-cp39-cp39-win_amd64.whl (5.2 MB)
Collecting itk-io==5.3rc4
  Using cached itk_io-5.3rc4-cp39-cp39-win_amd64.whl (8.5 MB)
Installing collected packages: numpy, itk-core, itk-numerics, itk-filtering, itk-segmentation, itk-registration, itk-io, itk, itk-elastix
Successfully installed itk-5.3rc4 itk-core-5.3rc4 itk-elastix-0.14.1 itk-filtering-5.3rc4 itk-io-5.3rc4 itk-numerics-5.3rc4 itk-registration-5.3rc4 itk-segmentation-5.3rc4 numpy-1.23.0
WARNING: You are using pip version 21.1.3; however, version 22.1.2 is available.
You should consider upgrading via the 'c:\a\pye\scripts\python.exe -m pip install --upgrade pip' command.

(pyE) C:\a>python
Python 3.9.6 (tags/v3.9.6:db3ff76, Jun 28 2021, 15:26:21) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import itk
>>> itk.elastix_registration_method
<function elastix_registration_method at 0x000001E5A6C43790>
>>>

@dzenanz
Copy link
Member

dzenanz commented Jun 28, 2022

One possible course of action: manually remove all traces of ITK from your Python installation, then install using pip install --pre itk-elastix.

@ntatsisk
Copy link
Collaborator

ntatsisk commented Jul 1, 2022

Thanks @dzenanz for trying to reproduce the error. It appears that it is related to the use of python through anaconda, but not to the mechanism of creating environments or the python version itself. More specifically, when I create a venv using the python executable in the conda installation I get the DLL error:

(base) C:\>C:\ProgramData\Miniconda3\python.exe -m venv pyE-conda-python

(base) C:\>.\pyE-conda-python\Scripts\activate

(pyE-conda-python) (base) C:\>pip install --pre itk-elastix
Collecting itk-elastix
  Using cached itk_elastix-0.14.1-cp39-cp39-win_amd64.whl (119.2 MB)
Collecting itk>=5.3rc4
  Using cached itk-5.3rc4-cp39-cp39-win_amd64.whl (8.3 kB)
Collecting itk-numerics==5.3rc4
  Using cached itk_numerics-5.3rc4-cp39-cp39-win_amd64.whl (20.2 MB)
Collecting itk-registration==5.3rc4
  Using cached itk_registration-5.3rc4-cp39-cp39-win_amd64.whl (9.1 MB)
Collecting itk-segmentation==5.3rc4
  Using cached itk_segmentation-5.3rc4-cp39-cp39-win_amd64.whl (5.2 MB)
Collecting numpy
  Using cached numpy-1.23.0-cp39-cp39-win_amd64.whl (14.7 MB)
Collecting itk-filtering==5.3rc4
  Using cached itk_filtering-5.3rc4-cp39-cp39-win_amd64.whl (24.0 MB)
Collecting itk-core==5.3rc4
  Using cached itk_core-5.3rc4-cp39-cp39-win_amd64.whl (36.1 MB)
Collecting itk-io==5.3rc4
  Using cached itk_io-5.3rc4-cp39-cp39-win_amd64.whl (8.5 MB)
Installing collected packages: numpy, itk-core, itk-numerics, itk-io, itk-filtering, itk-segmentation, itk-registration, itk, itk-elastix
Successfully installed itk-5.3rc4 itk-core-5.3rc4 itk-elastix-0.14.1 itk-filtering-5.3rc4 itk-io-5.3rc4 itk-numerics-5.3rc4 itk-registration-5.3rc4 itk-segmentation-5.3rc4 numpy-1.23.0
WARNING: You are using pip version 22.0.4; however, version 22.1.2 is available.
You should consider upgrading via the 'C:\pyE-conda-python\Scripts\python.exe -m pip install --upgrade pip' command.

(pyE-conda-python) (base) C:\>python
Python 3.9.12 (main, Apr  4 2022, 05:22:27) [MSC v.1916 64 bit (AMD64)] :: Anaconda, Inc. on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import itk
>>> itk.elastix_registration_method
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\pyE-conda-python\lib\site-packages\itk\support\lazy.py", line 138, in __getattribute__
    base.itk_load_swig_module(module, namespace)
  File "C:\pyE-conda-python\lib\site-packages\itk\support\base.py", line 96, in itk_load_swig_module
    itk_load_swig_module(dep, namespace)
  File "C:\pyE-conda-python\lib\site-packages\itk\support\base.py", line 96, in itk_load_swig_module
    itk_load_swig_module(dep, namespace)
  File "C:\pyE-conda-python\lib\site-packages\itk\support\base.py", line 96, in itk_load_swig_module
    itk_load_swig_module(dep, namespace)
  File "C:\pyE-conda-python\lib\site-packages\itk\support\base.py", line 132, in itk_load_swig_module
    l_module = loader.load(swig_module_name)
  File "C:\pyE-conda-python\lib\site-packages\itk\support\base.py", line 291, in load
    l_spec.loader.exec_module(l_module)  # pytype: disable=attribute-error
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "C:\pyE-conda-python\lib\site-packages\itk\support\..\ITKCommonPython.py", line 13, in <module>
    from . import _ITKCommonPython
ImportError: DLL load failed while importing _ITKCommonPython: The specified module could not be found.

However, if I use the system python instead (note that the python version is exactly the same!), it works:

(base) C:\>C:\Users\Gebruiker\AppData\Local\Programs\Python\Python39\python.exe -m venv pyE-system-python

(base) C:\>.\pyE-system-python\Scripts\activate

(pyE-system-python) (base) C:\>pip install --pre itk-elastix
Collecting itk-elastix
  Using cached itk_elastix-0.14.1-cp39-cp39-win_amd64.whl (119.2 MB)
Collecting itk>=5.3rc4
  Using cached itk-5.3rc4-cp39-cp39-win_amd64.whl (8.3 kB)
Collecting itk-io==5.3rc4
  Using cached itk_io-5.3rc4-cp39-cp39-win_amd64.whl (8.5 MB)
Collecting itk-numerics==5.3rc4
  Using cached itk_numerics-5.3rc4-cp39-cp39-win_amd64.whl (20.2 MB)
Collecting itk-segmentation==5.3rc4
  Using cached itk_segmentation-5.3rc4-cp39-cp39-win_amd64.whl (5.2 MB)
Collecting itk-filtering==5.3rc4
  Using cached itk_filtering-5.3rc4-cp39-cp39-win_amd64.whl (24.0 MB)
Collecting numpy
  Using cached numpy-1.23.0-cp39-cp39-win_amd64.whl (14.7 MB)
Collecting itk-core==5.3rc4
  Using cached itk_core-5.3rc4-cp39-cp39-win_amd64.whl (36.1 MB)
Collecting itk-registration==5.3rc4
  Using cached itk_registration-5.3rc4-cp39-cp39-win_amd64.whl (9.1 MB)
Installing collected packages: numpy, itk-core, itk-numerics, itk-io, itk-filtering, itk-segmentation, itk-registration, itk, itk-elastix
Successfully installed itk-5.3rc4 itk-core-5.3rc4 itk-elastix-0.14.1 itk-filtering-5.3rc4 itk-io-5.3rc4 itk-numerics-5.3rc4 itk-registration-5.3rc4 itk-segmentation-5.3rc4 numpy-1.23.0
WARNING: You are using pip version 22.0.4; however, version 22.1.2 is available.
You should consider upgrading via the 'C:\pyE-system-python\Scripts\python.exe -m pip install --upgrade pip' command.

(pyE-system-python) (base) C:\>python
Python 3.9.12 (tags/v3.9.12:b28265d, Mar 23 2022, 23:52:46) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import itk
>>> itk.elastix_registration_method
<function elastix_registration_method at 0x00000250610374C0>
>>>

I will investigate it further, but any ideas are welcome!

@ntatsisk
Copy link
Collaborator

As in InsightSoftwareConsortium/ITKPythonPackage#194, I tested again with itk-5.3.0 and I see that the issue mentioned here is also resolved. Btw, no need for --pre anymore.

Side note - does it make sense to bump the minimum itk version for itk-elastix from 5.3rc4.post4 to 5.3.0? @thewtex @tbirdso

@tbirdso
Copy link
Collaborator

tbirdso commented Nov 28, 2022

Hi @ntatsisk , glad to hear this has been resolved. Yes, we should bump itk-elastix for the ITK v5.3.0 release.

@N-Dekker
Copy link
Collaborator Author

Just checked at PR SuperElastix/elastix#762: SuperElastix/elastix builds fine with ITK tag v5.3.0 (no need to wait for PR SuperElastix/elastix#762 to be merged, it just works).

@thewtex thewtex closed this as completed Feb 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants