3

これは Stackoverflow に関する私の最初の質問です。私の質問が明確であることを願っています。

個人プロジェクト用に streamlit アプリをパッケージ化しようとしています。Linux で開発していますが、アプリを Windows にデプロイする必要があります。一度実行するとブラウザー タブを開いてアプリを表示し、タブを閉じると終了するスタンドアロンの実行可能ファイルにしたいと考えています。pynsistアプリをパッケージ化するためにライブラリを使用したいと思います(すでに別のプロジェクトで使用されており、正常に機能しました)。

このディスカッションで見つかった提案に従いました。アプリをpynsistでパッケージ化した後、ubuntu、および明らかにWindowsでも正常に機能しました。「どうやら」実行可能ファイルは実行されましたが、アプリを表示するためのブラウザー タブが開いていなかったためです。

これが私のコードの一部です。

プロジェクトの構造

|- installer.cfg
|- src
    |- main.py
    |- run_app.py

main.py

import streamlit as st

st.title("Test")
st.title("My first app deployed with Pynsist!")

run_app.py ( Thomas K によるコメントの後にEDIT 2 )

import os
import subprocess
import sys

from src.config import EnvironmentalVariableNames as EnvVar, get_env

def main():
    executable = sys.executable
    result = subprocess.run(
        f"{executable} -m streamlit run {os.path.join(get_env(EnvVar.EMPORIO_VESTIARIO_DASHBOARD_WORKING_DIR), 'src', 'main.py')}",
        shell=True,
        capture_output=True,
        text=True,
    )


if __name__ == "__main__":
    main()

EMPORIO_VESTIARIO_DASHBOARD_WORKING_DIRアプリを Linux と Windows の両方で動作させるための環境変数です (Windows では、インストール ディレクトリに設定されます)。

pynsistインストーラー.cfg

編集:を通じて発見された streamlit の依存関係を含むpip list

編集 2: Jinja2 の依存関係として MarkupSafe を追加

[Application]
name=Emporio Vestiario Dashboard
version=0.1.0
# How to lunch the app - this calls the 'main' function from the 'myapp' package:
entry_point=src.run_app:main
icon=resources/caritas-logo.ico

[Python]
version=3.8.10
bitness=64

[Include]
# Packages from PyPI that your application requires, one per line
# These must have wheels on PyPI:
pypi_wheels = altair==4.1.0
    astor==0.8.1
    attrs==21.2.0
    backcall==0.2.0
    backports.zoneinfo==0.2.1
    base58==2.1.0
    bleach==4.1.0
    blinker==1.4
    cachetools==4.2.2
    certifi==2021.5.30
    cffi==1.14.6
    charset-normalizer==2.0.6
    click==7.1.2
    decorator==5.1.0
    defusedxml==0.7.1
    distlib==0.3.3
    entrypoints==0.3
    idna==3.2
    jsonschema==3.2.0
    mistune==0.8.4
    mypy-extensions==0.4.3
    numpy==1.21.1
    packaging==21.0
    pandas==1.3.3
    pandocfilters==1.5.0
    parso==0.8.2
    pillow==8.3.2
    platformdirs==2.4.0
    prompt-toolkit==3.0.20
    protobuf==3.18.0
    pyarrow==5.0.0
    pycparser==2.20
    pydeck==0.7.0
    pyparsing==2.4.7
    pyrsistent==0.18.0
    python-dateutil==2.8.2
    pytz==2021.1
    requests==2.26.0
    requests-download==0.1.2
    send2trash==1.8.0
    setuptools==57.0.0
    six==1.14.0
    smmap==4.0.0
    streamlit==0.89.0
    terminado==0.12.1
    testpath==0.5.0
    toml==0.10.2
    tomli==1.2.1
    toolz==0.11.1
    tornado==6.1
    traitlets==5.1.0
    typing-extensions==3.10.0.2
    tzlocal==3.0
    urllib3==1.26.7
    validators==0.18.2
    Jinja2==3.0.1
    MarkupSafe==2.0.1

Windows で実行可能な出力を見ると、現在の作業ディレクトリは正しく出力されていますが、他の出力 (streamlit アプリの初期化メッセージまたはエラー メッセージ) は出力されていません。ブラウザを開いて にアクセスしようとしましたlocalhost:8501が、接続エラーが発生しました。

コードを実行してブラウザタブを自動的に開く方法に関するヒントはありますか? どんな助けでも大歓迎です!

編集:の最後のパッケージへのコメントで指摘されているようにinstaller.cfg、アプリ (Jinja2 依存関係を持つ) は Windows に正しくインストールされていますが、アプリを起動すると、まだ Jinja2 依存関係が見つかりません。これはトレースバックです:

Traceback (most recent call last):
  File "Emporio_Vestiario_Dashboard.launch.pyw", line 34, in <module>
    from src.run_app import main
  File "C:\Users\tantardini\develop\caritas\pkgs\src\run_app.py", line 6, in <module>
    import streamlit
  File "C:\Users\tantardini\develop\caritas\pkgs\streamlit\__init__.py", line 75, in <module>
    from streamlit.delta_generator import DeltaGenerator as _DeltaGenerator
  File "C:\Users\tantardini\develop\caritas\pkgs\streamlit\delta_generator.py", line 70, in <module>
    from streamlit.elements.arrow import ArrowMixin
  File "C:\Users\tantardini\develop\caritas\pkgs\streamlit\elements\arrow.py", line 20, in <module>
    from pandas.io.formats.style import Styler
  File "C:\Users\tantardini\develop\caritas\pkgs\pandas\io\formats\style.py", line 49, in <module>
    jinja2 = import_optional_dependency("jinja2", extra="DataFrame.style requires jinja2.")
  File "C:\Users\tantardini\develop\caritas\pkgs\pandas\compat\_optional.py", line 118, in import_optional_dependency
    raise ImportError(msg) from None
ImportError: Missing optional dependency 'Jinja2'. DataFrame.style requires jinja2. Use pip or conda to install Jinja2.

編集 2:トーマス K による役立つヒントのおかげで、解決策の半分を思いつきました。アプリが実行され、streamlit が開始されます。

しかし。

ログ メッセージは次のとおりです。

  Welcome to Streamlit!

  If you're one of our development partners or you're interested in getting
  personal technical support or Streamlit updates, please enter your email
  address below. Otherwise, you may leave the field blank.

  Email:
2021-10-11 20:56:53.202 WARNING streamlit.config:
Warning: the config option 'server.enableCORS=false' is not compatible with 'server.enableXsrfProtection=true'.
As a result, 'server.enableCORS' is being overridden to 'true'.

More information:
In order to protect against CSRF attacks, we send a cookie with each request.
To do so, we must specify allowable origins, which places a restriction on
cross-origin resource sharing.

If cross origin resource sharing is required, please disable server.enableXsrfProtection.
           
2021-10-11 20:56:53.202 DEBUG   streamlit.logger: Initialized tornado logs
2021-10-11 20:56:53.202 ERROR   streamlit.credentials: 

資格情報を待機しているため、アプリの実行が停止しているようです。ここで aを追加できることがわかりました.streamlit/credentials.tomlが、Windows の正確な場所はわかりません。--server.headless=falseまた、subprocess.runコマンドに明示的に追加しようとしましたが、効果はありません。

Linux のようにアプリが自動的に起動しないのはなぜですか? ユーザーが追加の構成を行わずにアプリを起動する方法はありますか?

4

1 に答える 1