pydicom / deid

best effort anonymization for medical images using python
https://pydicom.github.io/deid/
MIT License
140 stars 43 forks source link

ImportError: cannot import name 'get_private' #160

Closed vpapaioannou closed 3 years ago

vpapaioannou commented 3 years ago

Running from deid.dicom import get_private I get the error ImportError: cannot import name 'get_private' while I can see get_private function in deid/dicom/tags.py file. For e.g. get_identfiers the from deid.dicom import get_identifiers works fine.

I see remove_private lies within another file while it appears relevant to get_private. Is there a reason for that?

Thanks.

vsoch commented 3 years ago

If the function is in the file deid.dicom.tags then you need to import it from there :) The other functions (get_identifiers, replace_identifiers) are provided one level up for ease of use, but get_private is not as commonly used and thus needs to be imported from the module where it's defined.

vpapaioannou commented 3 years ago

I what sense are they one level up? Because they exist in another file instead of tags. Using died.dicom.tags works.

Thanks.

vsoch commented 3 years ago

So the functions get_identifiers and replace_identifiers are defined in deid.dicom.headers. When I say one level up, I mean that they are imported into the dicom/__init__.py (see here https://github.com/pydicom/deid/blob/master/deid/dicom/__init__.py). This means that either of these imports works for those functions:

from deid.dicom import get_identifiers
from deid.dicom.header import get_identifiers

But this is not the case for get_private. The design is modeled after pydicom, which also provides a subset of functions at the top level as a courtesy. https://github.com/pydicom/pydicom/blob/master/pydicom/__init__.py#L32

vpapaioannou commented 3 years ago

Thank you again! It's clear now.