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

Debugging #42

Open
dimi-colossal opened this issue Apr 21, 2024 · 1 comment
Open

Debugging #42

dimi-colossal opened this issue Apr 21, 2024 · 1 comment

Comments

@dimi-colossal
Copy link

I'm fairly new to both Python and FastAPI, so I might be missing an obvious solution here. I joined a team that's already working with said stack and they've set up a dev Docker image that runs the app through uvicorn. I see a similar setup in your repo.

Coming from Java, I'd prefer to run and debug the application without the need to run it inside a container (and also setting up remote debugging looks like a pain). Why is there a preference to run it in a container? I tried following FastAPI's suggested setup, but I quickly ran into some module import issues (probably due to my lack of deep Python understanding).

Any guidance on the reason for the design choice and possible bast practices would be welcome :)

@zhanymkanov
Copy link
Owner

Containers are great because they are easy to set up and run. Also, some networking isolation could be done, which is also nice. But, that is not an obligatory, nor a best practice - just a matter of choice.

If the module imports are not related to circular imports, then it is probably an improper server configuration. The best way that handles all the problems with it is to run the server from the project level, instead of the code level.

Here is the example:

- project/
-- src/
--- main.py
--- utils.py

If you attempt to run your code from the src directory using commands like python -m main, you are likely to encounter import issues with packages.

It's best to run the server from the project root directory, not from the src directory. Use the command python -m src.main from the project/ directory rather than python -m main from the src/ directory. This approach ensures that Python interprets your project structure correctly, resolving any import issues.

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