Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +15 -3
src/streamlit_app.py
CHANGED
@@ -21,11 +21,23 @@ with st.sidebar.form("install_lib_form"):
|
|
21 |
install_btn = st.form_submit_button("Install with pip")
|
22 |
if install_btn and lib_name.strip():
|
23 |
with st.spinner(f"Installing {lib_name}..."):
|
24 |
-
import subprocess
|
25 |
-
import sys
|
26 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
27 |
result = subprocess.run(
|
28 |
-
[
|
|
|
|
|
|
|
|
|
|
|
29 |
capture_output=True, text=True
|
30 |
)
|
31 |
if result.returncode == 0:
|
|
|
21 |
install_btn = st.form_submit_button("Install with pip")
|
22 |
if install_btn and lib_name.strip():
|
23 |
with st.spinner(f"Installing {lib_name}..."):
|
|
|
|
|
24 |
try:
|
25 |
+
# Define target directory for installation
|
26 |
+
target_dir = "/.local/lib/python3.9/site-packages"
|
27 |
+
os.makedirs(target_dir, exist_ok=True)
|
28 |
+
|
29 |
+
# Add to sys.path so imports work immediately
|
30 |
+
if target_dir not in sys.path:
|
31 |
+
sys.path.insert(0, target_dir)
|
32 |
+
|
33 |
+
# Run pip install into target dir
|
34 |
result = subprocess.run(
|
35 |
+
[
|
36 |
+
sys.executable, "-m", "pip", "install",
|
37 |
+
lib_name,
|
38 |
+
"--no-cache-dir",
|
39 |
+
"--target", target_dir
|
40 |
+
],
|
41 |
capture_output=True, text=True
|
42 |
)
|
43 |
if result.returncode == 0:
|