I am trying to install and run FastAPI in Termux. I install FastAPI successfully. But when I try to install uvicorn with pip install "uvicorn[standard]" I get this error. I can't paste the error here, because Stackoverflow identifies it as spam, here is a link
However, I successfully installed it with pip install uvicorn
.
But when I try uvicorn main:app --reload command
, I get this error
INFO: Will watch for changes in these directories: ['/data/data/com.termux/files/home/project/fapi']
INFO: Uvicorn running on http://0.0.0.0:8000 (Press CTRL+C to quit)
INFO: Started reloader process [11709] using watchgod
Traceback (most recent call last):
File "/data/data/com.termux/files/home/project/fapi/main.py", line 15, in <module>
uvicorn.run("main:app", host="0.0.0.0", port=8000, reload=True, access_log=False)
File "/data/data/com.termux/files/home/project/fapi/env/lib/python3.10/site-packages/uvicorn/main.py", line 442, in run
ChangeReload(config, target=server.run, sockets=[sock]).run()
File "/data/data/com.termux/files/home/project/fapi/env/lib/python3.10/site-packages/uvicorn/supervisors/basereload.py", line 43, in run
self.startup()
File "/data/data/com.termux/files/home/project/fapi/env/lib/python3.10/site-packages/uvicorn/supervisors/basereload.py", line 64, in startup
self.process.start()
File "/data/data/com.termux/files/usr/lib/python3.10/multiprocessing/process.py", line 121, in start
self._popen = self._Popen(self)
File "/data/data/com.termux/files/usr/lib/python3.10/multiprocessing/context.py", line 284, in _Popen
return Popen(process_obj)
File "/data/data/com.termux/files/usr/lib/python3.10/multiprocessing/popen_spawn_posix.py", line 32, in __init__
super().__init__(process_obj)
File "/data/data/com.termux/files/usr/lib/python3.10/multiprocessing/popen_fork.py", line 19, in __init__
self._launch(process_obj)
File "/data/data/com.termux/files/usr/lib/python3.10/multiprocessing/popen_spawn_posix.py", line 39, in _launch
from . import resource_tracker
File "/data/data/com.termux/files/usr/lib/python3.10/multiprocessing/resource_tracker.py", line 38, in <module>
import _posixshmem
ModuleNotFoundError: No module named '_posixshmem'
without --reload
the server runs, but as expected it doesn’t reload if code changes.
I tried same with hypercorn, doesn’t work. Seems like uvicorn and hypercorn can't be installed properly in Termux. Can anyone find another way of running fastapi in Termux with hot reloading.
Sorry for my bad English, I am not native English speaker. Also sorry if my question doesn’t follow guidelines, It’s my first question here.
Four months later, I tried again, It works. Back then, I posted an issue in Uvicorn github respiratory and though there was no solution, looks like they fixed it. Btw Uvicorn is using in StatReloader instead of WatchGodReloader in my android.