Cant access top level module from sub module
See original GitHub issueFirst Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn’t find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google “How to X in FastAPI” and didn’t find any information.
- I already read and followed all the tutorial in the docs and didn’t find an answer.
- I already checked if it is not related to FastAPI but to Pydantic.
- I already checked if it is not related to FastAPI but to Swagger UI.
- I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
- I commit to help with one of those options 👆
Example Code
from fastapi import Response, status, HTTPException, Depends, APIRouter
from sqlalchemy.orm.session import Session
from app import models, schemas
from app.database import get_db
Description
I cant access top level module from submodule
this is my structure
├─ app
├─main.py
├─ models.py
├─ schemas.py
|───router
│ ├─── __init__.py
│ ├─── post.py
│ └─── user.py
I want to access models and schemas for my post and user in router but I cant import all module from app I using relative and absolute import and yet python cant find all that
I believe import using the correct way as I following tutorial on official doc and reproduce the same structure from this https://github.com/tiangolo/full-stack-fastapi-postgresql
Operating System
Windows
Operating System Details
Windows 11
FastAPI Version
0.70.1
Python Version
Python 3.10.0
Additional Context
No response
Issue Analytics
- State:
- Created 2 years ago
- Comments:7
Top Results From Across the Web
Can't access top level python package from sub packages
My recommendation would be to change to the directory where the top-level modules and packages are (I guess cd path/to/chatbot/.. in your ...
Read more >importlib — The implementation of import — Python 3.11.1 ...
An abstract method for finding a spec for the specified module. If this is a top-level import, path will be None . Otherwise,...
Read more >Modules · The Julia Language
Main is the top-level module and the current module, when Julia is started. Standard library modules. By default Julia ships with some standard...
Read more >Python File Importation into Multi-Level Directory Modules and ...
As a Python programmer, it is a best practice to abstract application code into different files and directories and according to their related...
Read more >git-submodule Documentation - Git
Evaluates an arbitrary shell command in each checked out submodule. The command has access to the variables $name, $sm_path, $displaypath, $sha1 and $toplevel: ......
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
Yeah its works, iam using this
Iam tried to pip install -e . and make my project to the ediable state but I cant find the import
apreciate it
Something that you can also try is setting the path as an environment variable and accessing it using the OS library.