Render Deploy Failed? Fix Common Python Errors

Web Engineer

When a Python deploy fails on Render, start by opening "Logs" on the service page and reading the last error message. Most failures come down to one of five things: a wrong Start Command, a package missing from requirements.txt, the wrong port, a different Python version, or running out of memory on the free instance (512MB). This page lists the causes and fixes for each error message.

Updated December 2026: based on Render's official troubleshooting guide, added sections on ports (Port scan timeout), Python versions, out-of-memory errors and 502/503 errors, and updated the free-tier details (spin-down after 15 minutes, 512MB).

What is Render?

Render (Render.com) is a PaaS for deploying all kinds of web applications with little effort. Connected to GitHub, it deploys automatically on every push, and its free instance type makes it a popular place to publish portfolio projects. Heroku used to be the go-to choice, but Render drew attention after Heroku discontinued its free plans in November 2022.

A Free instance has 0.1 CPU and 512MB RAM, spins down after 15 minutes without traffic, and takes about a minute to start again on the next request (as of December 2026). Some errors are caused by these free-tier characteristics.

How to check the error log on Render

Open the service in the dashboard and go to "Logs" in the menu to see build and runtime logs. If a deploy failed, open that deploy from "Events" to see which stage (build or start) it stopped at. Rather than reading only the end of the log, look for the first line containing Error or Traceback.

Example Render log: a No open ports detected warning, followed by bash: npde: command not found and Exited with status 127
Log of a failed deploy (a typo in the Start Command). Source: Troubleshooting Your Deploy (Render Docs)

Quick reference

Message in the logCommon causeFix
ModuleNotFoundError: No module named 'your_application'The Start Command is still the placeholder gunicorn your_application.wsgiReplace it with your own file and app name
ModuleNotFoundError: No module named 'xxx'Package missing from requirements.txt / file name differs in letter caseAdd it to requirements.txt, check the spelling of paths
Port scan timeout reachedThe app is not listening on 0.0.0.0 and $PORTSet the host and port in the start command
requires Python >=3.x and similarRender's Python version differs from your local onePin the version with .python-version
Out of memoryExceeded the free instance's 512MBFewer workers, load less data, or upgrade the instance
502 Bad Gateway / WORKER TIMEOUTHeavy processing makes a gunicorn worker time outIncrease --timeout, reduce heavy work
503 Service UnavailableThe free instance is starting up after spinning downWait until it is up (about a minute)
ValueError: Unknown optimizer: Custom>...Compatibility issue when loading a Keras modelLoad it with compile=False
Render errors grouped by where the deploy stopped: build fails, start fails, and after going live, with the main errors and fixes for each
The errors from the quick reference, grouped by the stage where the deploy stopped

Error: ModuleNotFoundError: No module named 'your_application'

When you create a Python Web Service, the Start Command field contains the example gunicorn your_application.wsgi. If you leave it as is, Render tries to load a module called your_application, which does not exist, and you get this error.

Open the service's Settings and enter your own file name in Start Command. The example below is for a Python file named main.py.

Render Settings with the Start Command changed to match main.py

Here are example Start Commands by framework (replace the file and variable names with your own).

# Flask (app = Flask(__name__) in main.py)
gunicorn main:app --bind 0.0.0.0:$PORT

# Django (project named mysite)
gunicorn mysite.wsgi:application --bind 0.0.0.0:$PORT

# FastAPI (app = FastAPI() in main.py)
uvicorn main:app --host 0.0.0.0 --port $PORT

# Streamlit
streamlit run app.py --server.port $PORT --server.address 0.0.0.0

If you use gunicorn or uvicorn, they also need to be listed in requirements.txt.

Error: ModuleNotFoundError: No module named 'xxx' (a library)

When an app works locally but fails on Render, the cause is almost always a library installed only on your machine and missing from requirements.txt. Check that the Build Command is pip install -r requirements.txt and that every library you import is in requirements.txt.

The other common cause is letter case. Windows and macOS file systems are usually case-insensitive, so importing Utils.py with import utils works locally, but Render runs on Linux and won't find it. Make file names, directory names and extensions match exactly.

Error: Port scan timeout reached

Web services on Render must listen on host 0.0.0.0, on the port given in the PORT environment variable (default 10000). If the app starts on 127.0.0.1 (localhost), or Render can't find the port, the deploy fails. Set 0.0.0.0 and $PORT explicitly, as in the Start Command examples above. Render can often detect an app listening on a different port, but not reliably. Render also does not support binding to IPv6 addresses.

Listening on 127.0.0.1 leads to Port scan timeout reached; listening on 0.0.0.0 and $PORT (default 10000) lets the deploy succeed
Listen on 0.0.0.0:$PORT, not on localhost (127.0.0.1)

If you start Flask with app.run() (the development server), switching to gunicorn or similar for production is recommended.

Errors from a Python version mismatch

Installation can fail with messages like "requires Python >=3.x" when a library does not support the Python version being used. Render's default Python version depends on when the service was created; for services created on or after November 3, 2026, it is 3.14.x. If you depend on libraries that target older versions, pin the version with a .python-version file in the repository root.

3.12

You can also use the PYTHON_VERSION environment variable (it requires the patch number, such as 3.12.8, and takes precedence over the file).

Out of memory

A Free instance has 512MB of memory. Apps that load machine-learning models or large CSV files can run out of memory right after startup or on a request and keep restarting. Things to try:

  • Reduce the number of gunicorn workers (set the WEB_CONCURRENCY environment variable to a small value such as 1)
  • Load models and data only once at startup, and skip columns and rows you don't need
  • For large libraries such as TensorFlow, consider a lighter alternative (an inference-only runtime, for example)
  • If that is still not enough, switch to a paid instance (for example $7/month for 512MB or $25/month for 2GB)

502 Bad Gateway / 503 Service Unavailable

502 appears when the service could not handle the request. If the log shows WORKER TIMEOUT, something took longer than gunicorn's default timeout (30 seconds): extend it, as in gunicorn main:app --timeout 120, or reduce the heavy work. A wrong host or port can also cause 502, so check the previous section too.

503 on a Free instance usually means it is starting up after spinning down; wait about a minute and the page will load. Spinning down after 15 minutes without traffic is how the free tier works, not an error.

ValueError: Unknown optimizer: Custom>

This error only affects Keras users. It occurs when the optimizer definition at load time doesn't match the one used during training. If you only use the model for inference, loading it without compiling may solve it.

Before

model = load_model('./model.h5')

After

model = load_model('./model.h5', compile=False)

A model loaded with compile=False works with predict() but can't be retrained as is. If you need to retrain it, call model.compile() after loading. Keeping the same TensorFlow / Keras version in your training environment and on Render also reduces errors like this.

Related articles

References

Title and URL copied