Replies: 7 comments
-
|
Hi there, from what I've been researching seems that python3 doesn't allow to directly import as you have. Instead you might want to use the sys module or environment variables (which I believe is the best option) to optimize your imports. Then you can use the import method as usual. Try this and let me know if this works: import sys #Set the path to where the modules you're importing. #Here fastApi imports. from app import models, schemas |
Beta Was this translation helpful? Give feedback.
-
|
try to check |
Beta Was this translation helpful? Give feedback.
-
where I put those sys import ?? in main file or I must that on before init file ? |
Beta Was this translation helpful? Give feedback.
-
I already did that Yes is must be windows problem (windows sucks) because I dnt see it in anybody code |
Beta Was this translation helpful? Give feedback.
-
|
Could be even in the init file. However, I’d say it’s best practice to have it in the scripts where you need them. Try if it works in any file from your router dir. |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
|
Something that you can also try is setting the path as an environment variable and accessing it using the OS library. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
I cant access top level module from submodule
this is my structure
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
Beta Was this translation helpful? Give feedback.
All reactions