2 months ago
π§© Issue: FastAPI Deployment Fails with ModuleNotFoundError: No module named 'jose'
π Context
Iβm deploying a FastAPI backend (Python 3.12) on Railway using a split architecture:
- API service β
requirements.txt - Worker service β
requirements-worker.txt - Procfile:
web: uvicorn backend.main:app --host 0.0.0.0 --port $PORT The app works locally without issues, but fails after deployment.
π¨ Error Observed
From Railway logs:
ModuleNotFoundError: No module named 'jose'
π
Stack trace shows failure during import:
from backend.app.core.jwt import create_access_token, decode_token
from jose import jwt, JWTError
π¦ Dependencies (Relevant Section)
requirements.txt includes:
fastapi==0.115.0
uvicorn[standard]==0.30.0
pydantic[email]==2.6.1
sqlalchemy==2.0.25
psycopg2-binary==2.9.9
asyncpg==0.29.0
python-jose[cryptography]==3.3.0 β INCLUDED
passlib[bcrypt]==1.7.4
argon2-cffi==23.1.0
So the missing module should be installed.
π What I Already Verified
- App imports successfully locally
python-jose[cryptography]is present inrequirements.txt- No duplicate or conflicting dependency entries
- No lazy import issues (JWT is required at startup)
- Worker-related dependencies separated correctly
- API does NOT import Celery / Redis at startup
π§ͺ Observed Behavior
- Railway deploy succeeds
- Container starts
- Immediately crashes on startup due to missing
jose - Logs repeatedly show same import failure loop
π€ Suspected Cause
This looks like a build cache issue, where:
- Railway is not reinstalling dependencies
- Cached layer is reused
python-josenever gets installed in runtime environment
β Questions
- Does Railway sometimes skip dependency installation due to caching, even when
requirements.txtchanges? - What is the recommended way to force a clean rebuild?
- Is there a known issue with:
- Python 3.12 + Nixpacks
- Optional dependency syntax like
python-jose[cryptography]?
- Should I:
- Clear build cache manually?
- Delete & recreate the service?
- Use a custom build command?
π§― Temporary Workarounds Tried
- Added new lines to
requirements.txtto force rebuild - Re-deployed multiple times
- Verified Procfile and entrypoint
Still facing the same issue.
Expected Behavior
App should start successfully and expose:
/docs (Swagger UI)
/openapi.json
π Help Needed
Looking for guidance on:
- Forcing dependency reinstall on Railway
- Diagnosing build cache issues
- Any known compatibility issues with
python-jose
2 Replies
Status changed to Awaiting Railway Response Railway β’ about 2 months ago
2 months ago
This is clearly an application-level issue (Python dependency/configuration problem) it's likely not the correct
requirements.txtStatus changed to Awaiting User Response Railway β’ about 2 months ago
angelo-railway
This is clearly an application-level issue (Python dependency/configuration problem) it's likely not the correct ``` requirements.txt ```
2 months ago
requirements.txtfastapi==0.115.0
uvicorn[standard]==0.30.0
pydantic[email]==2.6.1
python-dotenv==1.0.1
python-multipart==0.0.9
sqlalchemy==2.0.25
alembic==1.13.1
psycopg2-binary==2.9.9
asyncpg==0.29.0
databases==0.9.0
python-jose[cryptography]==3.3.0
passlib[bcrypt]==1.7.4
argon2-cffi==23.1.0
pandas==2.2.2
openpyxl==3.1.5
PyMuPDF==1.24.9
boto3==1.34.162
openai==1.40.6
tenacity==8.5.0
# force-rebuild-3
Status changed to Awaiting Railway Response Railway β’ about 2 months ago
Status changed to Open Railway β’ about 2 months ago
Status changed to Solved loveleetsaini β’ about 2 months ago