Issue: FastAPI Deployment Fails with ModuleNotFoundError: No module named 'jose'
loveleetsaini
FREEOP

a month ago

jigsaw emoji Issue: FastAPI Deployment Fails with ModuleNotFoundError: No module named 'jose'

pushpin emoji 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.

rotating_light emoji 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.

mag emoji What I Already Verified

  • white_check_mark emoji App imports successfully locally

  • white_check_mark emojipython-jose[cryptography] is present in requirements.txt

  • white_check_mark emoji No duplicate or conflicting dependency entries

  • white_check_mark emoji No lazy import issues (JWT is required at startup)

  • white_check_mark emoji Worker-related dependencies separated correctly

  • white_check_mark emoji API does NOT import Celery / Redis at startup

test_tube emoji Observed Behavior

  • Railway deploy succeeds

  • Container starts

  • Immediately crashes on startup due to missing jose

  • Logs repeatedly show same import failure loop

thinking emoji Suspected Cause

This looks like a build cache issue, where:

  • Railway is not reinstalling dependencies

  • Cached layer is reused

  • python-jose never gets installed in runtime environment

question emoji Questions

  1. Does Railway sometimes skip dependency installation due to caching, even when requirements.txt changes?

  2. What is the recommended way to force a clean rebuild?

  3. Is there a known issue with:

    • Python 3.12 + Nixpacks

    • Optional dependency syntax like python-jose[cryptography]?

  4. Should I:

    • Clear build cache manually?

    • Delete & recreate the service?

    • Use a custom build command?

fire_extinguisher emoji Temporary Workarounds Tried

  • Added new lines to requirements.txt to force rebuild

  • Re-deployed multiple times

  • Verified Procfile and entrypoint

Still facing the same issue.

dart emoji 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

Solved$10 Bounty

2 Replies

Status changed to Awaiting Railway Response Railway about 1 month ago


This is clearly an application-level issue (Python dependency/configuration problem) it's likely not the correct

requirements.txt

Status changed to Awaiting User Response Railway about 1 month ago


angelo-railway

This is clearly an application-level issue (Python dependency/configuration problem) it's likely not the correctrequirements.txt

loveleetsaini
FREEOP

a month ago

requirements.txt

fastapi==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 1 month ago


Status changed to Open Railway about 1 month ago


Status changed to Solved loveleetsaini about 1 month ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...