question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] No module named 'dataclasses' under Python 3.6

See original GitHub issue

Describe the bug

Under FastAPI 0.49.0 and Python 3.6, a simple API throws an exception:

File "./app/__init__.py", line 1, in <module>
--
  | from fastapi import FastAPI
  | File "/opt/app-root/lib/python3.6/site-packages/fastapi/__init__.py", line 7, in <module>
  | from .applications import FastAPI
  | File "/opt/app-root/lib/python3.6/site-packages/fastapi/applications.py", line 3, in <module>
  | from fastapi import routing
  | File "/opt/app-root/lib/python3.6/site-packages/fastapi/routing.py", line 6, in <module>
  | from fastapi.dependencies.models import Dependant
  | File "/opt/app-root/lib/python3.6/site-packages/fastapi/dependencies/models.py", line 3, in <module>
  | from fastapi.security.base import SecurityBase
  | File "/opt/app-root/lib/python3.6/site-packages/fastapi/security/__init__.py", line 2, in <module>
  | from .http import (
  | File "/opt/app-root/lib/python3.6/site-packages/fastapi/security/http.py", line 5, in <module>
  | from fastapi.exceptions import HTTPException
  | File "/opt/app-root/lib/python3.6/site-packages/fastapi/exceptions.py", line 3, in <module>
  | from fastapi.utils import PYDANTIC_1
  | File "/opt/app-root/lib/python3.6/site-packages/fastapi/utils.py", line 2, in <module>
  | from dataclasses import is_dataclass
  | ModuleNotFoundError: No module named 'dataclasses'

To Reproduce

  1. Create a simple API:
from fastapi import FastAPI

app = FastAPI(title='example', description='just a test', docs_url='/', redoc_url=None)

@app.get('/api/test')
async def index(foo: str = 'default', bar: str = None):
    return {
        'foo': foo,
        'bar': bar
    }
  1. Attempt to run the API under Python 3.6 and observe the thrown exception

Expected behavior

The API should be available and not raise an exception. However, it does work under Python 3.7.

Environment

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
command-tabcommented, Feb 18, 2020

Ohhh, you know what, my local development environment is Python 3.7.x. I’ll bet that Pipfile.lock doesn’t include dataclasses because this environment didn’t need it, but my OpenShift production environment needs it because it’s 3.6. I bet if I were using a requirements.txt file instead of a full-graph lockfile, this wouldn’t be an issue.

0reactions
tiangolocommented, Apr 6, 2020

Thanks for the help here @dmontagu 🍰 🙇‍♂️

Thanks @command-tab for reporting back and closing the issue 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

No module named 'dataclasses' in Python 3.6.9 #1645 - GitHub
Python 3.6 doesn't have dataclasses, so the following fails: Traceback (most recent call last): File "…/.venv/bin/black", line 7, in from ...
Read more >
ModuleNotFoundError: No module named 'dataclasses'
While running below imports , I am getting the mentioned error - ModuleNotFoundError: No module named 'dataclasses' from fastai.imports ...
Read more >
Failed to import dataclasses module - python - Stack Overflow
The problem is that I can't seem to import dataclasses. I even tried installing the dataclasses module with pip3: pip3 install dataclasses ....
Read more >
ModuleNotFoundError: No module named 'dataclasses' when ...
When I tried to import the package (import refinitiv.dataplatform as rdp), I kept telling that data classes could not be found.
Read more >
How to Solve modulenotfounderror no module named ...
Make sure you are using Python 3.7 or above · Make sure you have imported the module · Install the dataclasses library ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found