Termux에 FastAPI를 설치하는 사람들은 별로 없나보다. 설치에 관한 글을 찾아보기 어렵다. Termux에 FastAPI를 설치해보면 여러 에러와 마주한다. 초기 Windows Arm에 파이썬을 설치하면서도 비슷한 경험을 했는데 비슷했다.
FastAPI는 pydantic과 rust 컴파일러에 의존한다. 즉, 이 둘을 설치하면 문제 없이 설치될 것이다. 다음은 설치하면서 겪은 상황과 해결방법을 연대기순으로 기재한 것이다.
Welcome to Termux!
~ $
~ $
~ $ python -m pip install fastapi
Collecting fastapi
Collecting pydantic-core==2.10.1 (from pydantic!=1.8,!=1.8.1,!=2.0.0,!=2.0.1,!=2.1.0,<3.0.0,>=1.7.4->fastapi)
Downloading pydantic_core-2.10.1.tar.gz (347 kB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Installing build dependencies ... error
error: subprocess-exited-with-error
To update pip, run:
pip install --upgrade pip
~ $
~ $
~ $ pip install --upgrade pip
ERROR: Installing pip is forbidden, this will break the python-pip package (termux).
~ $ python -m pip install python-pip를 한 후 다시 해도 같은 에러 메시지 나옴
~ $
~ $
~ $ python -m pip install pydantic
Collecting pydantic
Collecting pydantic-core==2.10.1 (from pydantic)
Using cached pydantic_core-2.10.1.tar.gz (347 kB)
Installing build dependencies ... error
error: subprocess-exited-with-error
.
.
.
writing manifest file 'maturin.egg-info/SOURCES.txt'
running build_ext
running build_rust
error: can't find Rust compiler
~ $
~ $
~ $ pkg install build-essential (이건 필수인지 불명확)
~ $
~ $
~ $ pkg install rust
The following NEW packages will be installed: rust
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
~ $
~ $
~ $ python -m pip install pydantic
Collecting pydantic
.
.
running: ZERO_AR_DATE="1" "aarch64-linux-android-ar" "cq" "/data/data/com.termux/files/usr/tmp/pip-install-ga4k_f2y/maturin_4c7e7394b9b94a15b4efb00902807651/target/release/build/psm-618e8718022be54d/out/libpsm_s.a" "/data/data/com.termux/files/usr/tmp/pip-install-ga4k_f2y/maturin_4c7e7394b9b94a15b4efb00902807651/target/release/build/psm-618e8718022be54d/out/src/arch/aarch_aapcs64.o"
--- stderr
error occurred: Failed to find tool. Is `aarch64-linux-android-ar` installed?
~ $
~ $
~ $ pkg install binutils
The following additional packages will be installed:
binutils-bin binutils-libs
The following NEW packages will be installed:
binutils binutils-bin binutils-libs
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 2765 kB of archives.
After this operation, 19.3 MB of additional disk space will be used.
Do you want to continue?
~ $
~ $
~ $ python -m pip install pydantic
Successfully installed
~ $
~ $
~ $ python -m pip install fastapi
Requirement already satisfied: annotated-types>=0.4.0 in /data/data/com.termux/files/usr/lib/python3.11/site-packages (from pydantic!=1.8,!=1.8.1,!=2.0.0,!=2.0.1,!=2.1.0,<3.0.0,>=1.7.4->fastapi) (0.6.0)
Requirement already satisfied: pydantic-core==2.10.1 in /data/data/com.termux/files/usr/lib/python3.11/site-packages (from pydantic!=1.8,!=1.8.1,!=2.0.0,!=2.0.1,!=2.1.0,<3.0.0,>=1.7.4->fastapi) (2.10.1)
Downloading fastapi-0.103.2-py3-none-any.whl (66 kB)
.
.
Successfully installed anyio-3.7.1 fastapi-0.103.2 idna-3.4 sniffio-1.3.0 starlette-0.27.0
반전은 FastAPI 설치가 완료되었다고 끝난게 아니었다. FastAPI 서버를 실행하면 휴대폰 내에서 localhost로 접속이 되지만, 동일 라우터 내 PC에서 안드로이드 아이피로 접속이 안 된다. 안드로이드 방화벽이 거의 모든 포트를 막고 있어 발생하는 현상으로 확인된다. 미봉책으로는 nmap을 통해 열린 포트를 찾아보는 것인데, 샤오미폰 기준으로 열린 포트는 없었다.
정리하자면, Termux에서 FastAPI 설치는