Import of MPRester fails
A new user here, trying an Materials project API. An attempt to import MPRester fails
In [1]: from pymatgen.ext.matproj import MPRester
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[1], line 1
----> 1 from pymatgen.ext.matproj import MPRester
File ~/opt/anaconda3/envs/eli/lib/python3.11/site-packages/pymatgen/ext/matproj.py:28
26 import requests
27 from monty.json import MontyDecoder, MontyEncoder
---> 28 from mp_api.client import MPRester as _MPResterNew
29 from ruamel.yaml import YAML
30 from tqdm import tqdm
File ~/opt/anaconda3/envs/eli/lib/python3.11/site-packages/mp_api/client/__init__.py:5
2 import os
3 from importlib.metadata import PackageNotFoundError, version
----> 5 from .core import MPRestError
6 from .mprester import MPRester
8 try:
File ~/opt/anaconda3/envs/eli/lib/python3.11/site-packages/mp_api/client/core/__init__.py:1
----> 1 from .client import BaseRester, MPRestError
2 from .settings import MAPIClientSettings
File ~/opt/anaconda3/envs/eli/lib/python3.11/site-packages/mp_api/client/core/client.py:20
17 from urllib.parse import quote, urljoin
19 import requests
---> 20 from emmet.core.utils import jsanitize
21 from monty.json import MontyDecoder
22 from pydantic import BaseModel, create_model
File ~/opt/anaconda3/envs/eli/lib/python3.11/site-packages/emmet/core/utils.py:25
22 from pymatgen.util.graph_hashing import weisfeiler_lehman_graph_hash
24 from emmet.core.mpid import MPculeID
---> 25 from emmet.core.settings import EmmetSettings
27 try:
28 import bson
File ~/opt/anaconda3/envs/eli/lib/python3.11/site-packages/emmet/core/settings.py:22
16 DEFAULT_CONFIG_FILE_PATH = str(Path.home().joinpath(".emmet.json"))
19 S = TypeVar("S", bound="EmmetSettings")
---> 22 class EmmetSettings(BaseSettings):
23 """
24 Settings for the emmet- packages
25 Non-core packages should subclass this to get settings specific to their needs
26 The default way to modify these is to modify ~/.emmet.json or set the environment variable
27 EMMET_CONFIG_FILE to point to the json with emmet settings
28 """
30 config_file: str = Field(
31 DEFAULT_CONFIG_FILE_PATH, description="File to load alternative defaults from"
32 )
File ~/opt/anaconda3/envs/eli/lib/python3.11/site-packages/pydantic/main.py:186, in pydantic.main.ModelMetaclass.__new__()
TypeError: Argument 'bases' has incorrect type (expected list, got tuple)
Relevant versions and platform info:
- OS: MacOS Monterey
- Version pymatgen-2023.7.20
- Python 3.11.2
@estavitski What version of mp-api are you using? Have you tried pip install --update mp-api?
@janosh mp-api 0.33.3 pyhd8ed1ab_0 conda-forge
That's outdated. Try the latest RC.
0.33.3 should still be okay. Which version of pydantic do you have installed?
@munrojm pydantic 1.10.12 py311h2725bcf_0 conda-forge
Hm, okay. I can't reproduce so far. Which version of emmet-core do you have?
@munrojm
updated to pydantic 2.1.1, and now I get
PydanticImportError: BaseSettingshas been moved to thepydantic-settings` package. See https://docs.pydantic.dev/2.1.1/migration/#basesettings-has-moved-to-pydantic-settings for more details.
For further information visit https://errors.pydantic.dev/2.1.1/u/import-error `
@munrojm
emmet-core 0.63.1
FWIW when I tried to pip install --upgrade emmet-core it did that
Installing collected packages: pydantic Attempting uninstall: pydantic Found existing installation: pydantic 2.1.1 Uninstalling pydantic-2.1.1: Successfully uninstalled pydantic-2.1.1 Successfully installed pydantic-1.10.12
@estavitski Yes, pydantic 1.10.12 should be good. We are planning on support >2.0 soon.
Does this import error happen for you if you directly import from mp-api?
from mp_api.client import MPRester
@munrojm Ha! No. Thanks!
Glad it is an easy fix. It definitely shouldn't be erroring out just by importing through pymatgen though, so @janosh and I will have to investigate that.
I think this might be an environment issue. Does the original error still happen for you @estavitski now? And if so, can you reproduce it in a clean environment?
@janosh you were right. (eli) elistavitski@10-4-5-112 ~ % conda create --name test python=3.11 (eli) elistavitski@10-4-5-112 ~ % conda activate test (test) elistavitski@10-4-5-112 ~ % conda install --channel conda-forge pymatgen (test) elistavitski@10-4-5-112 ~ % conda install ipython (test) elistavitski@10-4-5-112 ~ % ipython Python 3.11.4 (main, Jul 5 2023, 08:41:25) [Clang 14.0.6 ] Type 'copyright', 'credits' or 'license' for more information IPython 8.12.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: from pymatgen.ext.matproj import MPRester
In [2]: