I had no luck via the requirements.txt route either What worked was installing the package in the main app script itself via a subprocess.
Say your script is streamlit_app.py. Include the following at the very top of your app:
import streamlit as st
import subprocess
import sys
import time
try:
# replace "yourpackage" with the package you want to import
import yourpackage
# This block executes only on the first run when your package isn't installed
except ModuleNotFoundError as e:
subprocess.Popen([f'{sys.executable} -m pip install git+https://${{token}}@github.com/yourusername/yourrepo.git'], shell=True)
# wait for subprocess to install package before running your actual code below
time.sleep(90)
# Rest of your code goes here
import yourpackage
st.write(yourpackage.somefunc())
In the secrets management console paste in your token like so:
I am facing the same problem when trying to install a private GitHub repo and unfortunately keep getting the error
fatal: could not read Username for 'https://github.com': No such device or address
error: subprocess-exited-with-error
even after I tried the proposed solution of @snehankekre to generate the personal access token and install the package in the main script. Did anybody come up with a workaround in the mean time or made it work with the proposed code?