Title: [SOLVED] Streamlit Cloud Deployment Fails with TensorFlow/YOLOv8 - Python Version Mismatch
Hi everyone,
I’ve been working on a real-time gesture recognition app using a stack of YOLOv8, MediaPipe, and TensorFlow/Keras. While the app runs perfectly on my local machine, I ran into a persistent deployment error on Streamlit Cloud.
I wanted to share the problem and check if anyone else faces the same issue.
The App:
- Goal: Real-time gesture recognition from a webcam.
- Stack:
streamlit
,streamlit-webrtc
,ultralytics
(for YOLOv8),mediapipe
,tensorflow
. - GitHub Repo: GitHub - chmj/app_yolodetect: Real-Time Gesture Recognition App
The Problem: Dependency Resolution Failure
After pushing my repository, the Streamlit Cloud deployment would fail every time. The logs showed a clear error during the dependency installation phase:
Using Python 3.13.5 environment at /home/adminuser/venv
...
ERROR: Could not find a version that satisfies the requirement tensorflow==2.15.0 (from versions: none)
ERROR: No matching distribution found for tensorflow==2.15.0
The key issue was that the Streamlit Cloud server was defaulting to Python 3.13, but a compatible version of TensorFlow (and its dependencies) was not available for that specific Python version. Pinning the library versions in requirements.txt
alone was not enough to solve this.
The Solution: Forcing the Python Version (suggested by gemini) - It does’t work.
Part 1: Pinning All Dependencies
First, I created a requirements.txt
file with specific, known-to-work versions of all the major libraries. This prevents pip
from trying to install the latest (and potentially incompatible) versions.
requirements.txt
:
# For computer vision
opencv-python==4.8.1.78
ultralytics==8.0.221
tensorflow==2.15.0
mediapipe==0.10.9
torch==2.1.2
torchvision==0.16.2
# For web app
streamlit==1.36.0
streamlit-webrtc==0.47.0
aiortc==1.6.0
Part 2: Specifying the Python Version (The Critical Step)
This was the key to solving the problem. I had to explicitly tell Streamlit Cloud which Python version to use. This is done by adding a configuration file to the repository.
- Create a new folder in the root of the repository named
.streamlit
(with a leading dot). - Inside that folder, create a new file named
config.toml
. - Add the following content to
config.toml
:
.streamlit/config.toml
:
[server]
pythonVersion = "3.11"
This configuration forces the Streamlit Cloud environment to use Python 3.11, which is fully compatible with the library versions specified in the requirements.txt
file.
After committing both of these files, the deployment still broke with the same error. Any ideas?