Skip to content

cannot import name 'ModelMetaclass' from 'pydantic.main #9

@shinkwee

Description

@shinkwee

I found I cannot import he nis2pyr to python.
I use the following command line and received a import error.
from nis2pyr.convertor import convert_nd2_to_pyramidal_ome_tiff
The issue seems to be the authors of pydantic made ModelMetaclass private in recent version.

File ~/anaconda3/envs/nis2pyr/lib/python3.8/site-packages/nis2pyr/convertor.py:3
1 import nd2
2 from typing import Optional
----> 3 from nis2pyr.writer import write_pyramidal_ome_tiff
6 def convert_nd2_to_pyramidal_ome_tiff(nd2_filename: str,
7 pyramid_filename: str,
8 compression: Optional[str] = None,
9 tile_size: int = 256,
10 max_levels: int = 6) -> None:
11 """Convert an ND2 file to a tiled pyramidal OME TIFF file.
12
13 Args:
(...)
23 including the full resolution original.
24 """

File ~/anaconda3/envs/nis2pyr/lib/python3.8/site-packages/nis2pyr/writer.py:8
4 import tifffile # https://github.com/cgohlke/tifffile
6 from typing import Optional, Tuple
----> 8 from nis2pyr.metadata import update_channels_info, get_ome_voxelsize
9 from nis2pyr.reader import read_nd2file
10 from nis2pyr import version

File ~/anaconda3/envs/nis2pyr/lib/python3.8/site-packages/nis2pyr/metadata.py:1
----> 1 import ome_types
2 import tifffile
3 from typing import Any, Dict, List, Optional, Tuple

File ~/anaconda3/envs/nis2pyr/lib/python3.8/site-packages/ome_types/init.py:9
6 version = "unknown"
8 try:
----> 9 from . import model
10 from .model import OME
11 except ModuleNotFoundError as e:

File ~/anaconda3/envs/nis2pyr/lib/python3.8/site-packages/ome_types/model/init.py:1
----> 1 from .affine_transform import AffineTransform
2 from .annotation import Annotation
3 from .annotation_ref import AnnotationRef

File ~/anaconda3/envs/nis2pyr/lib/python3.8/site-packages/ome_types/model/affine_transform.py:1
----> 1 from ome_types._base_type import OMEType
4 class AffineTransform(OMEType):
5 """A matrix used to transform the shape.
6
7 ⎡ A00, A01, A02 ⎤ ⎢ A10, A11, A12 ⎥ ⎣ 0, 0, 1 ⎦
(...)
16 a12 : float
17 """

File ~/anaconda3/envs/nis2pyr/lib/python3.8/site-packages/ome_types/_base_type.py:13
1 from typing import (
2 TYPE_CHECKING,
3 Any,
(...)
9 no_type_check,
10 )
12 from pydantic import BaseModel, validator
---> 13 from pydantic.main import ModelMetaclass
15 if TYPE_CHECKING:
16 import pint

ImportError: cannot import name 'ModelMetaclass' from 'pydantic.main' (/home/kuanwei/anaconda3/envs/nis2pyr/lib/python3.8/site-packages/pydantic/main.py)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions