One package needs to download linux zip, giving permission error

Hi,

Hi everyone,

I’m encountering a PermissionError when deploying a Python app that uses the whitebox package. This package attempts to automatically download a binary (WhiteboxTools_linux_amd64.zip) upon execution, but it fails due to permission issues on the server. The error message is:

PermissionError: [Errno 13] Permission denied: ‘/home/adminuser/venv/lib/python3.11/site-packages/whitebox/WhiteboxTools_linux_amd64.zip’

The app runs fine locally, but the issue arises when deploying to a server environment where the user might not have the necessary permissions to write to the Python site-packages directory.

Does anyone have suggestions on how to handle this? Is there a way to pre-download the binary or configure the whitebox package to avoid this automatic download process during runtime? Any advice on how to resolve or work around this issue would be greatly appreciated.

Thank you!

I managed to make it work.

import io
import os
import stat
import zipfile
from pathlib import Path

import requests
import streamlit as st
import whitebox

WBT_PATH = "WhiteboxTools_linux_amd64/WBT"
WBT_URL = "https://www.whiteboxgeo.com/WBT_Linux/WhiteboxTools_linux_amd64.zip"


def download_wbt():
    response = requests.get(WBT_URL)
    with zipfile.ZipFile(io.BytesIO(response.content), "r") as zip_ref:
        zip_ref.extractall()
    exe_path = WBT_PATH + "/whitebox_tools"
    st_result = os.stat(exe_path)
    os.chmod(exe_path, st_result.st_mode | stat.S_IEXEC)


if not Path(WBT_PATH).exists():
    download_wbt()

os.environ["WBT_PATH"] = WBT_PATH
wbt = whitebox.WhiteboxTools()
wbt.set_whitebox_dir(WBT_PATH)
st.write(wbt.version())

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