DeepDriveMD / DeepDriveMD-pipeline

DeepDriveMD: Deep-Learning Driven Adaptive Molecular Simulations
MIT License
15 stars 9 forks source link

ImportError: cannot import name 'root_validator' from 'pydantic' #33

Closed lee212 closed 3 years ago

lee212 commented 3 years ago

In the course of testing DDMD on Bridges2, this is observed:

Traceback (most recent call last):
  File "/jet/home/sanjrani/DeepDriveMD-pipeline/deepdrivemd/agents/lof/lof.py", line 13, in <module>
    from deepdrivemd.agents.lof.config import OutlierDetectionConfig
  File "/jet/home/sanjrani/DeepDriveMD-pipeline/deepdrivemd/agents/lof/config.py", line 2, in <module>
    from pydantic import root_validator, validator
ImportError: cannot import name 'root_validator' from 'pydantic' (/jet/home/sanjrani/anaconda3/envs/conda-pytorch/lib/python3.8/site-packages/pydantic/__init__.py)
nsanjrani commented 3 years ago

Changing PyTorch virtual environment from python-3.8.10 to python-3.6.12 solved the issue as the required version is older than 3.7 (https://github.com/samuelcolvin/pydantic/blob/master/requirements.txt)

braceal commented 3 years ago

I believe pydantic is supported in all Python versions greater than or equal to 3.6+, see the the readme: https://github.com/samuelcolvin/pydantic#pydantic

And see pypi: https://pypi.org/project/pydantic/

I'm not exactly sure what the python_version < '3.7' requirement does, but perhaps it is not use to build the released versions.

Here is a test case that verifies the latest version of pydantic in Python 3.7:

$ python -V
Python 3.7.4
$ python -m venv env
$ source env/bin/activate
(env) $ pip install pydantic
Collecting pydantic
  Downloading https://files.pythonhosted.org/packages/ff/74/54e030641601112309f6d2af620774e9080f99c7a15742fc6a0b170c4076/pydantic-1.8.2-py3-none-any.whl (126kB)
    100% |████████████████████████████████| 133kB 7.9MB/s
Collecting typing-extensions>=3.7.4.3 (from pydantic)
  Using cached https://files.pythonhosted.org/packages/2e/35/6c4fff5ab443b57116cb1aad46421fb719bed2825664e8fe77d66d99bcbc/typing_extensions-3.10.0.0-py3-none-any.whl
Installing collected packages: typing-extensions, pydantic
Successfully installed pydantic-1.8.2 typing-extensions-3.10.0.0
You are using pip version 19.0.3, however version 21.1.3 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(env) $ python
Python 3.7.4 (default, Aug 13 2019, 20:35:49)
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pydantic
>>> pydantic.VERSION
'1.8.2'
>>> from pydantic import root_validator, validator
>>>

This could point to another issue with the conda environment.

nsanjrani commented 3 years ago

You're right there must have been something wrong with the installation onto that conda environment, I ended up making a new one which seemed to work. Also, we checked this before as well but importing root_validator and validator from pydantic seemed to work in terminal regardless of which environment was activated but threw the error running on the cluster. I'm not sure if this is relevant but in the __init__.py file that it was complaining about before, the root_validator module wasn't actually imported from .class_validators but in the new installation it is.

braceal commented 3 years ago

Glad it is working now. I'll close the issue, but feel free to reopen if the error pops up again.