Help with lightgbm on codespaces

Hello everyone,

I am very new to streamlit and trying to deploy my first app.
I have used a model to predict board game ratings, which worked fine locally but when I deployed it I got “ModuleNotFoundError: No module named 'lightgbm” error.

When I edit it on codespaces, the app seems to run without any problems in the simple browser, as well.

I have checked some of the suggestions I could find online, such as updating requirements.txt to include lightgbm,

Link to my app is :
and link to my repo is: GitHub - SeckinD/Streamlit

any help will be much appreciated.

Hi @Seckind

The ModuleNotFoundError typically tells us that a dependent library is missing and should be installed.

As you had mentioned that you had added lightgbm to requirements.txt, this should resolve the issue. If not, it may be resolved by rebooting the app.

I’ve created a simple lightgbm use case here:

The requirements.txt for this is:


And the file is as follows:

import streamlit as st
import pandas as pd
import numpy as np
import lightgbm as lgb
from sklearn.model_selection import train_test_split
from sklearn.metrics import r2_score
from sklearn import metrics

st.title('🎈 LightGBM')

# Load data
df = pd.read_csv('')

# Separate data as X, y
X = df.iloc[:,:-1]
y = df.iloc[:,-1]

# Data split
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.8, random_state=42)

# Model training
model = lgb.LGBMRegressor(learning_rate=0.09, max_depth=-5, random_state=42, force_col_wise=True), y_train)

# Model performance
y_train_pred = model.predict(X_train)
y_test_pred = model.predict(X_test)

st.write('Train *R*\u00b2: {:.3f}'.format(r2_score(y_train, y_train_pred)))
st.write('Test *R*\u00b2: {:.3f}'.format(r2_score(y_test, y_test_pred)))

This was deployed successfully on Community Cloud and the demo app is available at:

Hope this helps!

1 Like

Thank you @dataprofessor for taking the time to build the demo app.
Indeed, rebooting the app seems to have solved the problem (who could have thought? :man_facepalming:)
Really appreciate the input!

1 Like

Glad that the problem has been resolved and yes sometimes resolves app problems.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.