Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poetry installation raises ImportError: cannot import name 'Schema' from 'pydantic' #1010

Closed
realyashnag opened this issue Feb 24, 2023 · 9 comments

Comments

@realyashnag
Copy link

Hey everyone,
Apparently the dependencies are not correctly resolved by poetry here.

yash@ezpzpc:~/Desktop/mycoolapp/ml/app$ poetry run python --version
Python 3.8.10
yash@ezpzpc:~/Desktop/mycoolapp/ml/app$ poetry add mlserver

yields the following:

Package operations: 45 installs, 0 updates, 0 removals

  • Installing frozenlist (1.3.3)
  • Installing greenlet (2.0.2)
  • Installing idna (3.4)
  • Installing multidict (6.0.4)
  • Installing sniffio (1.3.0)
  • Installing zope.event (4.6)
  • Installing zope.interface (5.5.2)
  • Installing aiosignal (1.3.1)
  • Installing anyio (3.6.2)
  • Installing async-timeout (4.0.2)
  • Installing attrs (22.2.0)
  • Installing brotli (1.0.9)
  • Installing certifi (2022.12.7)
  • Installing charset-normalizer (3.0.1)
  • Installing gevent (22.10.2)
  • Installing six (1.16.0)
  • Installing typing-extensions (4.5.0)
  • Installing yarl (1.8.2)
  • Installing aiohttp (3.8.4): Installing...
  • Installing click (8.1.3): Installing...
  • Installing click (8.1.3): Installing...
  • Installing aiohttp (3.8.4)
  • Installing click (8.1.3): Installing...
  • Installing click (8.1.3)
  • Installing geventhttpclient (2.0.2)
  • Installing grpcio (1.52.0)
  • Installing h11 (0.14.0)
  • Installing kafka-python (2.0.2)
  • Installing numpy (1.24.2)
  • Installing packaging (23.0)
  • Installing prometheus-client (0.16.0)
  • Installing pydantic (1.10.5)
  • Installing python-dateutil (2.8.2)
  • Installing python-rapidjson (1.9)
  • Installing pytz (2022.7.1)
  • Installing starlette (0.25.0)
  • Installing aiofiles (23.1.0)
  • Installing aiokafka (0.8.0)
  • Installing fastapi (0.1.17)
  • Installing orjson (3.8.6)
  • Installing pandas (1.5.3)
  • Installing protobuf (4.22.0)
  • Installing py-grpc-prometheus (0.7.0)
  • Installing python-dotenv (1.0.0)
  • Installing starlette-exporter (0.15.1)
  • Installing tritonclient (2.30.0)
  • Installing uvicorn (0.20.0)
  • Installing uvloop (0.17.0)
  • Installing mlserver (1.2.3)

Now upon running the mlserver:

yash@ezpzpc:~/Desktop/mycoolapp/ml/app$ poetry run mlserver start .
Traceback (most recent call last):
  File "/home/yash/Desktop/mycoolapp/ml/app/.venv/bin/mlserver", line 5, in <module>
    from mlserver.cli import main
  File "/home/yash/Desktop/mycoolapp/ml/app/.venv/lib/python3.8/site-packages/mlserver/__init__.py", line 2, in <module>
    from .server import MLServer
  File "/home/yash/Desktop/mycoolapp/ml/app/.venv/lib/python3.8/site-packages/mlserver/server.py", line 7, in <module>
    from .model import MLModel
  File "/home/yash/Desktop/mycoolapp/ml/app/.venv/lib/python3.8/site-packages/mlserver/model.py", line 3, in <module>
    from .codecs import (
  File "/home/yash/Desktop/mycoolapp/ml/app/.venv/lib/python3.8/site-packages/mlserver/codecs/__init__.py", line 1, in <module>
    from .numpy import NumpyCodec, NumpyRequestCodec
  File "/home/yash/Desktop/mycoolapp/ml/app/.venv/lib/python3.8/site-packages/mlserver/codecs/numpy.py", line 8, in <module>
    from .utils import SingleInputRequestCodec, InputOrOutput, inject_batch_dimension
  File "/home/yash/Desktop/mycoolapp/ml/app/.venv/lib/python3.8/site-packages/mlserver/codecs/utils.py", line 22, in <module>
    from .errors import CodecError
  File "/home/yash/Desktop/mycoolapp/ml/app/.venv/lib/python3.8/site-packages/mlserver/codecs/errors.py", line 4, in <module>
    from ..errors import MLServerError
  File "/home/yash/Desktop/mycoolapp/ml/app/.venv/lib/python3.8/site-packages/mlserver/errors.py", line 1, in <module>
    from fastapi import status
  File "/home/yash/Desktop/mycoolapp/ml/app/.venv/lib/python3.8/site-packages/fastapi/__init__.py", line 5, in <module>
    from .applications import FastAPI
  File "/home/yash/Desktop/mycoolapp/ml/app/.venv/lib/python3.8/site-packages/fastapi/applications.py", line 3, in <module>
    from fastapi import routing
  File "/home/yash/Desktop/mycoolapp/ml/app/.venv/lib/python3.8/site-packages/fastapi/routing.py", line 6, in <module>
    from fastapi import params
  File "/home/yash/Desktop/mycoolapp/ml/app/.venv/lib/python3.8/site-packages/fastapi/params.py", line 4, in <module>
    from pydantic import Schema
ImportError: cannot import name 'Schema' from 'pydantic' (/home/yash/Desktop/mycoolapp/ml/app/.venv/lib/python3.8/site-packages/pydantic/__init__.cpython-38-x86_64-linux-gnu.so)

This error suggests downgrading pydantic version to 1.7 or lower, but then it raises this issue instead.

@adriangonz
Copy link
Contributor

Hey @realyashnag ,

It looks like Poetry is installing a really old version of FastAPI there. It's installing 0.1.17 (from Jan 2019), when MLServer should work with (up to) 0.89.1.

Do you know why that could be the case?

@stephen37
Copy link
Contributor

We also had the same problem, on my side to fix it I explicitly added fastapi as a dependency with poetry.
poetry add fastapi, it then installed FastAPI 0.92 and solved the problem. No idea why poetry fetches a version that old though

@stephen37
Copy link
Contributor

Also so we found the problem cc @franco-bocci , it's because MLServer doesn't have a lower limit so poetry installs a very old version. It is possible to fix it by providing a lower limit for FastAPI package in setup.py, by doing so, poetry will resolve a version of FastAPI that isn't too old.

I added a PR that solves this problem.

@adriangonz
Copy link
Contributor

Hey @stephen37,

I think it may be worth raising this question on the Poetry community. We need to know more about why Poetry is fetching such an old version of FastAPI to ensure this doesn't come back in the future.

Generally package managers will try to fetch the latest version according to the constrains. If poetry is not following that assumption, then do we need to lower-bound every other dependency in MLServer? What would happen with transient dependencies?

@franco-bocci
Copy link

@adriangonz , I agree that it's not strictly a MLServer problem. However, not lower constraining this cause issues as it directly does not work.
If there is a known dependency version that causes issues, shouldn't it be excluded?

@stephen37
Copy link
Contributor

Yeah as Franco said, maybe we can simply remove fastapi<=0.89.1 in setup.py and only keeps !=0.89.0
https://github.com/SeldonIO/MLServer/blob/master/setup.py#LL45C27-L45C35

What do you think? I guess it was the only problematic one with MLServer right?

@adriangonz
Copy link
Contributor

Totally agree @franco-bocci @stephen37 - we can go ahead and patch fastapi, which would unblock this one.

However, my main concern is whether this may also be impacting other dependencies that we don't know about (e.g. other cases within MLServer where Poetry is quietly picking a really old version). This would end up in inconsistent environments that may break unexpectedly.

That's why I think it's worth it to understand what's going from the Poetry side so that we can fix it properly. Is this something that you could raise with the Poetry team @franco-bocci @stephen37?

@stephen37
Copy link
Contributor

Yes, I'll check poetry and create an issue there as well if I can. It should go in descending order in that case as well

@adriangonz
Copy link
Contributor

adriangonz commented Apr 20, 2023

Hey @stephen37 @franco-bocci @realyashnag , given that #1033 has already been merged I'll close this one for now.

Having said that, once you hear back from the Poetry team, I'd be more than happy to continue the discussion on what we can do better!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants