Skip to content
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

Uvicorn import paths different than main.py’s, difficulties debugging #68

Closed
jdittrich opened this issue Mar 15, 2022 · 2 comments
Closed

Comments

@jdittrich
Copy link

jdittrich commented Mar 15, 2022

(I hope I describe this correctly, it is possible that I have a misunderstanding of how imports are resolved)

Problem: The FastAPI documentation on debugging suggests to call uvicorn directly from main via the IDE/Debugger. However, in this case, fastapi-nano’s imports do not seem to work, as the folder of main.py is the root folder for the module imports with this method of executing the code. So from app.core import auth fails, , from core import auth would work. The imports work when calling uvicorn directly since uvicorn app.main:app (as documented in the readme) seems to make the module resolution uses the folder uvicorn was called from as its root (that is, the project’s main folder with the folder app in it)

Possible solutions:

  • Assume calling from the /app folder and change paths accordingly
  • Document another way to debug
  • Dont fix/not a significant problem
@rednafi
Copy link
Owner

rednafi commented Mar 16, 2022

from core import auth comes with its fair share of issues. Can you try python -m main instead of running the main module as a script? Running python main.py puts the path of the nested package to the top of the sys.path which can have other unintended consequences. You can learn more about it here:

https://rednafi.github.io/reflections/how-not-to-run-a-script-in-python.html

@rednafi
Copy link
Owner

rednafi commented Apr 18, 2022

Not an issue.

@rednafi rednafi closed this as completed Apr 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants