[Python] Read write on local drive through Streamlit application as executable (built using...

Discussão em 'Python' iniciado por Stack, Fevereiro 20, 2025.

  1. Stack

    Stack Membro Participativo

    new to streamlit and have no experience with npm. I have created streamlit app and packaged it as an executable .exe following a tutorial https://youtu.be/3wZ7GRbr91g?si=8FLBt3PsAxvEEzjo . streamlit graphs/ functions (buttons, filters etc.) is working fine using package.json I created as follow,


    {
    "name": "95L_schedule",
    "version": "0.4.0",
    "main": "./build/electron/main.js",
    "scripts": {
    "dump": "dump-stlite-desktop-artifacts",
    "serve": "cross-env NODE_ENV=production electron .",
    "servewindows": "electron .",
    "pack": "electron-builder --dir",
    "dist": "electron-builder",
    "postinstall": "electron-builder install-app-deps"
    },
    "build": {
    "files": ["build/**/*"],
    "directories": {
    "buildResources": "assets"
    },
    "win": {
    "target": "portable"
    }
    },
    "devDependencies": {
    "@stlite/desktop": "^0.76.0",
    "cross-env": "^7.0.3",
    "electron": "^33.0.1",
    "electron-builder": "^25.1.8"
    },
    "stlite": {
    "desktop": {
    "files": ["streamlit_app/app.py"],
    "entrypoint": "streamlit_app/app.py",
    "dependencies": ["numpy", "pandas", "plotly-express"]
    }
    }
    }

    And then in the windows command prompt


    npm install
    npm run dump numpy pandas matplotlib
    npm run dist

    through my streamlit code, I want to be able to write files (save matplotlib figures) on the local drive where this executable is running.

    I tried accessing the current working directory with something like below but it does not work, I am assuming executable is running in some sort of npm shell and not on windows itself.


    with st.form(key='create_prints'):
    submit_button = st.form_submit_button(label='create printable files')

    if submit_button:
    base_path = os.getcwd() + "/" + assign['start_timestamp'].min().strftime('%Y%m%d') + "/"
    os.makedirs(base_path + "machines/", exist_ok=True)

    How should I go about it? thank you!

    Continue reading...

Compartilhe esta Página