'Faust doesn't like relative path
I'm trying to clean up my code and have moved the models.py file to the top level, as other modules other than the faust ones will use this now. The folder structure is below (albeit cut down for simplicity)
App
|
├── models
| ├── models.py
|
├── kafka
| ├── agent_a.py
|
├── servers
| ├── fastapi_server.py
Both the fastapi_server.py
and the agent_a.py
need access to models.py
. If I run the server from the App
directory it works ok. But when I try to run the following to start the faust agent also from the App directory it returns a No module named 'kafka.agent_a'
error:
C:\path\to\App> faust -A kafka.agent_a:app worker
What is strange is that when I run the same command from a completely different directory that just has the faust/kafka stuff in there it works. What could possibly be happening for it to report the error?
But also note that when I run the server using:
C:\path\to\App> uvicorn servers.fastapi_server:app
it doesn't complain about the module at all. And if I try to run the faust application using:
C:\path\to\App> python kafka\agent_a.py worker
It then complains about the models not being a module. So I'm just completely confused about why one python script runs ok and the other doesn't... but it does run normally in a different directory
I've always found imports in python ridiculous to get my head around, but this one is significantly more stupefying.
Solution 1:[1]
Renaming the directory as suggested above did kind of solve the issue, but we still do have a relative imports issue that is a python problem, not a Faust one. But the import issue is completely resolvable with the use of the terminal commands, so we'll just stick with that.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Fonty |