Streamlit Cloud app no longer runs (PermissionError: [Errno 13]), worked before and was not changed

The application was running perfectly fine before the summer, and runs fine locally. However, now it gets errors when running in the Streamlit Cloud.

In a bit more detail, the application installs python packages using pip and a requirement file.
The package sund is used for simulating models, and the models must be compiled. When trying to compile the model files, there is a permission error. Below is a short excerpt of the log file.

Any ideas on what could be the issue? Has anything changed that would now give this issues that were not happening before the summer?

2023-09-05 09:19:19.748 Uncaught app exception
Traceback (most recent call last):
  File "/home/adminuser/venv/lib/python3.9/site-packages/setuptools/sandbox.py", line 156, in save_modules
    yield saved
  File "/home/adminuser/venv/lib/python3.9/site-packages/setuptools/sandbox.py", line 194, in setup_context
    with override_temp(temp_dir):
  File "/usr/local/lib/python3.9/contextlib.py", line 119, in __enter__
    return next(self.gen)
  File "/home/adminuser/venv/lib/python3.9/site-packages/setuptools/sandbox.py", line 74, in override_temp
    os.makedirs(replacement, exist_ok=True)
  File "/usr/local/lib/python3.9/os.py", line 225, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/home/adminuser/venv/lib/python3.9/site-packages/sund/temp'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/adminuser/venv/lib/python3.9/site-packages/sund/tools.py", line 70, in _modelModuleFile
    sandbox.run_setup(os.path.join(_sundFolder,'_setupModel_.py'), ['build_ext', '-b', os.path.dirname(_sundFolder), 'clean', cfile])
  File "/home/adminuser/venv/lib/python3.9/site-packages/setuptools/sandbox.py", line 249, in run_setup
    with setup_context(setup_dir):
  File "/usr/local/lib/python3.9/contextlib.py", line 119, in __enter__
    return next(self.gen)
  File "/home/adminuser/venv/lib/python3.9/site-packages/setuptools/sandbox.py", line 198, in setup_context
    yield
  File "/usr/local/lib/python3.9/contextlib.py", line 137, in __exit__
    self.gen.throw(typ, value, traceback)
  File "/home/adminuser/venv/lib/python3.9/site-packages/setuptools/sandbox.py", line 169, in save_modules
    saved_exc.resume()
  File "/home/adminuser/venv/lib/python3.9/site-packages/setuptools/sandbox.py", line 143, in resume
    raise exc.with_traceback(self._tb)
  File "/home/adminuser/venv/lib/python3.9/site-packages/setuptools/sandbox.py", line 156, in save_modules
    yield saved
  File "/home/adminuser/venv/lib/python3.9/site-packages/setuptools/sandbox.py", line 194, in setup_context
    with override_temp(temp_dir):
  File "/usr/local/lib/python3.9/contextlib.py", line 119, in __enter__
    return next(self.gen)
  File "/home/adminuser/venv/lib/python3.9/site-packages/setuptools/sandbox.py", line 74, in override_temp
    os.makedirs(replacement, exist_ok=True)
  File "/usr/local/lib/python3.9/os.py", line 225, in makedirs
    mkdir(name, mode)
PermissionError: [Errno 13] Permission denied: '/home/adminuser/venv/lib/python3.9/site-packages/sund/temp'

Hey @willov,

Thanks for sharing this question! Can you share a link to the GitHub repo for the app so we can try to reproduce this error?

I have created a “minimal” example which recreates the issue. The code is available here: GitHub - willov/streamlit_issue_example
And the corresponding Streamlit application is available here: https://error-13-example.streamlit.app/

Thanks!

1 Like

Looks like sund assumes it can pip-install packages in the environment where it is running. In Streamlit Cloud, however, the application has read-only access to the venv.

I guess you could pass a custom destination to pip install and add it to sys.path (not tested).

Thanks for the input! You are indeed correct that sund attempts to write files to the package location. Any idea as to why this was working before and now isn’t?

I tried removing sund from the requirements file, and installed it directly in the streamlit_app.py script instead using subprocess (snippet below).
However, this if course makes the application very slow because the package needs to be rebuilt all the time.
edit: The repeated installation can be bypassed by checking if the package is already installed

import subprocess
import sys
if "sund" not in os.listdir('./custom_package'):
subprocess.check_call([sys.executable, "-m", "pip", "install", "--target=./custom_package", 'https://isbgroup.eu/edu/assets/sund-1.0.1.tar.gz#sha256=669a1d05c5c8b68500086e183d831650277012b3ea57e94356de1987b6e94e3e'])

sys.path.append('./custom_package')
import sund

Is there a way to interact with pip before the streamlit_app.py file is run (in the Cloud)?

I don’t think so, other than modifying requirements.txt.

But in my view this is actually a sund issue where it incorrectly assumes that it can write to its installation directory at run time. That is a serious mistake and should be fixed. Or maybe sund.importModel() can take optional arguments to override that behavior?

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