Importerror: Cannot Import Name 'Annotated' from 'Pydantic. Typing' When Using Inflect Library in Python

Hello I am using Python 3.8

And I am trying to create a function to sort and print a list in the form of,

{first_element}, {second_element} and {last_element}

I've used the inflect library in Python to do this because it is expected to be used in my assignment.

import inflect
p = inflect.engine()

def sort():
    fruits = ["apple", "banana", "carrot"]
    mylist = p.join(fruits)
    print(mylist)

sort()

But when I execute this I get the following error:

Traceback (most recent call last):
  File "main.py", line 1, in <module>
    import inflect
  File "/home/username/.local/lib/python3.8/site-packages/inflect/__init__.py", line 77, in <module>
    from pydantic.typing import Annotated
ImportError: cannot import name 'Annotated' from 'pydantic.typing' (/home/username/.local/lib/python3.8/site-packages/pydantic/typing.py)

I tried reinstalling the library called Pydantic. But it didn't change anything.

1 Answer

Pydantic 2.0 was released a few hours ago which has introduced breaking changes for inflect.

Ideally, inflect should have had an upper max for pydantic version in their project. Track the issue on inflect here.


Check what version of pydantic is installed on your machine. It must be 2.0. You need to uninstall that and install the highest 1.xx.x.


I understand this answer will be obsolete once this issue resolves, but here are the only two things to do when such breaking changes are encountered:

  1. Check the version you have installed in your machine.
  2. Check for issues on the project's GitHub page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Sophia Al-Mansoor

Sophia Al-Mansoor

Global Business & E-Commerce Reporter

Sophia analyzes international trade, startup ecosystems, retail transformation, and supply chain logistics for modern digital publications.

Share this article
Twitter Facebook Pinterest