Skip to content

Conversation

@thewtex
Copy link
Member

@thewtex thewtex commented Jul 22, 2022

Addresses:

ImportError: PyCapsule_Import could not import module "_ITKCommonPython"

That can occur when unpickling for Dask, for example.

According to the PyCapsule_Import documentation, internally it calls
PyImport_ImportModule. According to the PyImport_ImportModule
documentation, this requires the absolute path -- we add the itk.
prefix.

In most other contexts, the _ITKCommonPython module is likely to
already be imported. Since _ITKCommonPython gets loaded via
PyImport_ImportModule, it is not registered with the ITK lazy loading
module system, so we add from . import _ITKCommon.

Addresses:

```
ImportError: PyCapsule_Import could not import module "_ITKCommonPython"
```

That can occur when unpickling for Dask, for example.

According to the `PyCapsule_Import` documentation, internally it calls
`PyImport_ImportModule`. According to the `PyImport_ImportModule`
documentation, this requires the absolute path -- we add the `itk.`
prefix.

In most other contexts, the `_ITKCommonPython` module is likely to
already be imported. Since `_ITKCommonPython` gets loaded via
PyImport_ImportModule, it is not registered with the ITK lazy loading
module system, so we add `from . import _ITKCommon`.
@github-actions github-actions bot added area:Python wrapping Python bindings for a class type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances labels Jul 22, 2022
Copy link
Contributor

@GenevieveBuckley GenevieveBuckley left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me. Thanks for working on it!

I can't say for sure it will for sure fix the dask example (I wasn't able to build ITK last time I tried, so I can't test it now), but I certainly can't see this causing any problems for either ITK or dask.

@hjmjohnson hjmjohnson merged commit 835dc01 into InsightSoftwareConsortium:master Jul 24, 2022
@PranjalSahu
Copy link
Contributor

import dask
import itk
from dask import delayed

if __name__== "__main__":
    from dask.distributed import Client, LocalCluster
    cluster = LocalCluster()
    client = Client(cluster)

    @delayed
    def performsum(m):
        return m.GetNumberOfPoints()

    m = itk.Mesh[itk.F, 3].New()
    a = performsum(m).compute()
    print(a)

Tested with a locally built wheel.
It works fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Python wrapping Python bindings for a class type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants