ModuleNotFoundError: No module named 'app' using uvicorn, fastapi
See original GitHub issueI am getting ModuleNotFoundError: No module named ‘app’ error.
Below (image) is almost everything you need to know about the issue. There have been other similar issues about this, but most of them were related to docker. I am not using docker and don’t know much about it.
This is a common problem I have observed. Any help is appreciated.
Complete Error
Process SpawnProcess-5:
Traceback (most recent call last):
File "/usr/lib/python3.6/multiprocessing/process.py", line 258, in _bootstrap
self.run()
File "/usr/lib/python3.6/multiprocessing/process.py", line 93, in run
self._target(*self._args, **self._kwargs)
File "/xxxxx/geoprocessing-api/.venv/lib/python3.6/site-packages/uvicorn/subprocess.py", line 61, in subprocess_started
target(sockets=sockets)
File "/xxxxx/geoprocessing-api/.venv/lib/python3.6/site-packages/uvicorn/server.py", line 48, in run
loop.run_until_complete(self.serve(sockets=sockets))
File "/usr/lib/python3.6/asyncio/base_events.py", line 484, in run_until_complete
return future.result()
File "/xxxxxx/geoprocessing-api/.venv/lib/python3.6/site-packages/uvicorn/server.py", line 55, in serve
config.load()
File "/xxxxxxx/geoprocessing-api/.venv/lib/python3.6/site-packages/uvicorn/config.py", line 308, in load
self.loaded_app = import_from_string(self.app)
File "/xxxxx/geoprocessing-api/.venv/lib/python3.6/site-packages/uvicorn/importer.py", line 23, in import_from_string
raise exc from None
File "/xxxxx/geoprocessing-api/.venv/lib/python3.6/site-packages/uvicorn/importer.py", line 20, in import_from_string
module = importlib.import_module(module_str)
File "/usr/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/xxxxxxxxx/geoprocessing-api/app/server/app.py", line 2, in <module>
from app.server.routes.config_route import router as ConfigRouter
ModuleNotFoundError: No module named 'app'
Please let me know if you need anything else. Thanks.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
ModuleNotFoundError: No module named 'app.routes'
Your uvicorn command is slightly off. From whatever directory is above app run -- uvicorn app.main:app --reload.
Read more >tiangolo/fastapi - Gitter
on docker: uvicorn main:app --host 0.0.0.0 --port 8000 --reload. euri10. @euri10 ... in your uvicorn command ... ModuleNotFoundError: No module named 'app'.
Read more >No module named 'app' " while running a FastAPI server?
I'm using environment variables with FastAPI, but I'm getting a "ModuleNotFoundError" error while running the server with uvicorn main:app --reload :
Read more >Can't find FastAPI module? - Reddit
app = FastAPI() ... ModuleNotFoundError: No module named 'fastapi' ... same error using the Python command line that I get using the uvicorn...
Read more >Testing - FastAPI
And the calls to the client are also normal calls, not using await . ... And your FastAPI application might also be composed...
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 Free
Top 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
@shawnwall, @Mause Thanks for the suggestions.
I found the reason for it. My PYTHONPATH environment variable was not set.
To set it, you can run the below command in the base directory of your project:
This fixed my issue and I was able to use the imports along with the app.server.x.x.
Thanks for your insights though.
Then you have to fix the new error, in a similar way