MolecularAI / QSARtuna

QSARtuna: QSAR model building with the optuna framework
https://molecularai.github.io/QSARtuna/
Apache License 2.0
101 stars 16 forks source link

ImportError: cannot import name '_collect_type_vars' from 'typing' (/home/zz/anaconda3/envs/my_env_with_qsartuna/lib/python3.11/typing.py)" } #38

Open mmsoda opened 1 day ago

mmsoda commented 1 day ago

Hi Lewis I am running the example notebook and the following error appeared.

{
    "name": "ImportError",
    "message": "cannot import name '_collect_type_vars' from 'typing' (/home/zz/anaconda3/envs/my_env_with_qsartuna/lib/python3.11/typing.py)",
    "stack": "---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[1], line 1
----> 1 from qsartuna.three_step_opt_build_merge import (
      2     optimize,
      3     buildconfig_best,
      4     build_best,
      5     build_merged,
      6 )
      7 from qsartuna.config import ModelMode, OptimizationDirection
      8 from qsartuna.config.optconfig import (
      9     OptimizationConfig,
     10     SVR,
   (...)
     14     XGBRegressor,
     15 )

File ~/anaconda3/envs/my_env_with_qsartuna/lib/python3.11/site-packages/qsartuna/__init__.py:8
      5 import optunaz
      6 from optunaz import *
----> 8 import optunaz.config.optconfig
      9 import optunaz.config.buildconfig
     10 import optunaz.descriptors

File ~/anaconda3/envs/my_env_with_qsartuna/lib/python3.11/site-packages/optunaz/config/__init__.py:9
      6 from pathlib import Path
      7 from typing import Optional, Any, Dict
----> 9 from apischema import deserialize
     11 from optunaz.utils import mkdict
     13 current_module_dir = os.path.dirname(os.path.abspath(__file__))

File ~/anaconda3/envs/my_env_with_qsartuna/lib/python3.11/site-packages/apischema/__init__.py:30
      1 __all__ = [
      2     \"PassThroughOptions\",
      3     \"Undefined\",
   (...)
     25     \"validator\",
     26 ]
     28 import warnings
---> 30 from . import (  # noqa: F401
     31     cache,
     32     conversions,
     33     dataclasses,
     34     fields,
     35     json_schema,
     36     metadata,
     37     objects,
     38     skip,
     39     tagged_unions,
     40     validation,
     41 )
     42 from .aliases import alias
     43 from .conversions import deserializer, serializer

File ~/anaconda3/envs/my_env_with_qsartuna/lib/python3.11/site-packages/apischema/cache.py:6
      3 from functools import lru_cache
      4 from typing import Callable, Iterator, MutableMapping, TypeVar, cast
----> 6 from apischema.utils import type_dict_wrapper
      8 _cached: list = []
     10 Func = TypeVar(\"Func\", bound=Callable)

File ~/anaconda3/envs/my_env_with_qsartuna/lib/python3.11/site-packages/apischema/utils.py:37
     11 from typing import (
     12     AbstractSet,
     13     Any,
   (...)
     33     cast,
     34 )
     36 from apischema.types import COLLECTION_TYPES, MAPPING_TYPES, PRIMITIVE_TYPES, AnyType
---> 37 from apischema.typing import (
     38     _collect_type_vars,
     39     generic_mro,
     40     get_args,
     41     get_origin,
     42     get_type_hints,
     43     is_annotated,
     44     is_type_var,
     45     is_union,
     46     typing_origin,
     47 )
     49 try:
     50     from apischema.typing import Annotated

File ~/anaconda3/envs/my_env_with_qsartuna/lib/python3.11/site-packages/apischema/typing.py:98
     95         pass
     97 if sys.version_info >= (3, 7):
---> 98     from typing import _collect_type_vars  # type: ignore
     99 else:
    100     from typing import _type_vars as _collect_type_vars

ImportError: cannot import name '_collect_type_vars' from 'typing' (/home/zz/anaconda3/envs/my_env_with_qsartuna/lib/python3.11/typing.py)"
}

I checked the typing.py file and only the _collect_parameters function was available. Do you guys get the same error when running the code? Many thanks

mmsoda commented 1 day ago

I downgraded the QSARtuna version (to 3.1.2) then everything is working as expected.