[BUG] No module named 'dataclasses' under Python 3.6
See original GitHub issueDescribe 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
- 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
}
- 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
- OS: Red Hat OpenShift, Python 3.6 container
- FastAPI Version: 0.49.0
- Python version: 3.6.3
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (4 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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.Thanks for the help here @dmontagu 🍰 🙇♂️
Thanks @command-tab for reporting back and closing the issue 👍