Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

ImportError: cannot import name Deque #2732

Closed
kkruzich opened this issue Jan 31, 2021 · 4 comments
Closed

ImportError: cannot import name Deque #2732

kkruzich opened this issue Jan 31, 2021 · 4 comments

Comments

@kkruzich
Copy link

First check

  • [ x] I added a very descriptive title to this issue.
  • [ x] I used the GitHub search to find a similar issue and didn't find it.
  • [ x] I searched the FastAPI documentation, with the integrated search.
  • [ x] I already searched in Google "How to X in FastAPI" and didn't find any information.
  • [ x] I already read and followed all the tutorial in the docs and didn't find an answer.
  • [ x] I already checked if it is not related to FastAPI but to Pydantic.
  • [ x] I already checked if it is not related to FastAPI but to Swagger UI.
  • [ x] I already checked if it is not related to FastAPI but to ReDoc.
  • [ x] After submitting this, I commit to one of:
    • Read open issues with questions until I find 2 issues where I can help someone and add a comment to help there.
    • I already hit the "watch" button in this repository to receive notifications and I commit to help at least 2 people that ask questions in the future.
    • Implement a Pull Request for a confirmed bug.

Example

Here's a self-contained, minimal, reproducible, example with my use case:

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
def read_root():
    return {"Hello": "World"}

Description

Python 3.6.0 (v3.6.0:41df79263a11, Dec 22 2016, 17:23:13)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from typing import Optional
>>> from fastapi import FastAPI
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/fastapi/__init__.py", line 7, in <module>
    from .applications import FastAPI as FastAPI
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/fastapi/applications.py", line 3, in <module>
    from fastapi import routing
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/fastapi/routing.py", line 18, in <module>
    from fastapi import params
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/fastapi/params.py", line 4, in <module>
    from pydantic.fields import FieldInfo
  File "pydantic/__init__.py", line 2, in init pydantic.__init__
  File "pydantic/dataclasses.py", line 4, in init pydantic.dataclasses
    import types
  File "pydantic/error_wrappers.py", line 4, in init pydantic.error_wrappers
  File "pydantic/json.py", line 12, in init pydantic.json
  File "pydantic/types.py", line 28, in init pydantic.types
    yield
  File "pydantic/validators.py", line 9, in init pydantic.validators
ImportError: cannot import name Deque

Environment

  • OS: macOS 10.15.3

To know the FastAPI version use:

python3 -c "import fastapi; print(fastapi.__version__)"
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/fastapi/__init__.py", line 7, in <module>
    from .applications import FastAPI as FastAPI
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/fastapi/applications.py", line 3, in <module>
    from fastapi import routing
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/fastapi/routing.py", line 18, in <module>
    from fastapi import params
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/fastapi/params.py", line 4, in <module>
    from pydantic.fields import FieldInfo
  File "pydantic/__init__.py", line 2, in init pydantic.__init__
  File "pydantic/dataclasses.py", line 4, in init pydantic.dataclasses
    import types
  File "pydantic/error_wrappers.py", line 4, in init pydantic.error_wrappers
  File "pydantic/json.py", line 12, in init pydantic.json
  File "pydantic/types.py", line 28, in init pydantic.types
    yield
  File "pydantic/validators.py", line 9, in init pydantic.validators
ImportError: cannot import name Deque
  • Python version:
Python 3.6.0

Additional context

@kkruzich kkruzich added the question Question or problem label Jan 31, 2021
@ycd
Copy link
Contributor

ycd commented Feb 1, 2021

Well it is backported twice for 3.5.4 and 3.6.0 (see issue #29481).

So you are probably using older version of 3.6.0. Best thing you can do is installing a newer version of Python.

@hukkin
Copy link
Contributor

hukkin commented Feb 1, 2021

It seems to me like typing.Deque was added in Python 3.6.1 (source: https://docs.python.org/3/library/typing.html#typing.Deque).

So FastAPI and Pydantic both seem to require Python >=3.6.1

Edit: I opened PRs to fix this in FastAPI and pydantic ( #2733 and pydantic/pydantic#2306 )

@tiangolo
Copy link
Owner

tiangolo commented Oct 5, 2021

Thanks for the report @kkruzich! 🤓

Thanks for the investigation @ycd! 🕵️

And thanks @hukkin for the PR updating the metadata! 👨‍🔬


Yep, you should probably update the Python version to 3.6.1 at least. Have in mind that 3.6 reaches the end of life in December, by then you should hopefully have upgraded to at least Python 3.7.

@github-actions
Copy link
Contributor

Assuming the original need was handled, this will be automatically closed now. But feel free to add more comments or create new issues or PRs.

@tiangolo tiangolo reopened this Feb 27, 2023
Repository owner locked and limited conversation to collaborators Feb 27, 2023
@tiangolo tiangolo converted this issue into discussion #6999 Feb 27, 2023

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Projects
None yet
Development

No branches or pull requests

4 participants