📓

streamlit を試してみる。 on GhostBSD

に公開

python でサクッと簡単にできるなにか!

https://streamlit.io/

データ・アプリケーションの構築と共有の高速化
Streamlitは、データスクリプトを数分で共有可能なウェブアプリに変えます。
すべてピュアなPythonで。フロントエンドの経験は必要ありません。

データの塊を、ウェブアプリで格好良く示したいときに便利ですね。
最近私好みの Pythonに業務の軸足を移してもいいと思うような便利なツールが山ほどあるので、Django/Flaskに宗旨替えよーかと思ってしまいます。

Pythonはゴリゴリとコード書くと論理ネスト地獄に落ちたりと、的確な論理構造で短くまとめるという素地の賢さが必要なので私のような脳筋には向かない感じですが・・・

GhostBSDでやってみたい・・・

ということで、ubuntuではすでに streamlit でなにかできたんですが・・・

strnh@ghostbsd ~/w/s/sample (main) [1]> pip install streamlit
Defaulting to user installation because normal site-packages is not writeable
Collecting streamlit
  Downloading streamlit-1.43.2-py2.py3-none-any.whl.metadata (8.9 kB)
Collecting altair<6,>=4.0 (from streamlit)
  Downloading altair-5.5.0-py3-none-any.whl.metadata (11 kB)
Collecting blinker<2,>=1.0.0 (from streamlit)
  Downloading blinker-1.9.0-py3-none-any.whl.metadata (1.6 kB)
Collecting cachetools<6,>=4.0 (from streamlit)
  Downloading cachetools-5.5.2-py3-none-any.whl.metadata (5.4 kB)
Requirement already satisfied: click<9,>=7.0 in /usr/local/lib/python3.11/site-packages (from streamlit) (8.1.7)
Requirement already satisfied: numpy<3,>=1.23 in /usr/local/lib/python3.11/site-packages (from streamlit) (1.26.4)
Requirement already satisfied: packaging<25,>=20 in /usr/local/lib/python3.11/site-packages (from streamlit) (24.2)
Collecting pandas<3,>=1.4.0 (from streamlit)
  Downloading pandas-2.2.3.tar.gz (4.4 MB)
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.4/4.4 MB 2.4 MB/s eta 0:00:00
  Installing build dependencies ... - 

本日も GhostBSD での作業日です。 最近は、ubuntu/ghostbsd/macOSを7:2:1 ぐらいの割合で使っています。 小生、GhostBSDの環境は、かなり古いPCに入れていますが、16GBにしたのでメモリの余裕はあれどやはり計算能力が足りてない模様。

  Installing build dependencies ... /

btopの様子
pandasのcompile

GhostBSDでは、スクリプト処理系はバイナリで突っ込めても、その後のコンパイルができなかったので、この手の作業を一旦は諦めていたのですが、 "Cコンパイラが動かない対策" を知ってしまって、入れたらコンパイルができるようになったもので嬉しさ余ってついつい・・・

コンパイルならず・・・

  • qt5Core をコンパイルしようとしてつまります・・・
                        CMake Error at /usr/local/lib/cmake/Qt5Core/Qt5CoreConfig.cmake:14 (message):
                          The imported target "Qt5::Core" references the file
      
                             "/usr/local/lib/qt5/bin/qmake"
      
                          but this file does not exist.  Possible reasons include:
      
                          * The file was deleted, renamed, or moved to another location.
      
                          * An install or uninstall procedure did not complete successfully.
      
                          * The installation package was faulty and contained
      
                             "/usr/local/lib/cmake/Qt5Core/Qt5CoreConfigExtras.cmake"
      
                          but not all the files it references.
      
                        Call Stack (most recent call first):
                          /usr/local/lib/cmake/Qt5Core/Qt5CoreConfigExtras.cmake:9 (_qt5_Core_check_file_exists)
                          /usr/local/lib/cmake/Qt5Core/Qt5CoreConfig.cmake:232 (include)
                          /usr/local/lib/cmake/Qt5Gui/Qt5GuiConfig.cmake:99 (find_package)
                          /usr/local/lib/cmake/Qt5Widgets/Qt5WidgetsConfig.cmake:99 (find_package)
                          Tests/CMakeLists.txt:248 (find_package)
      
      
                        -- Configuring incomplete, errors occurred!
                        gmake[2]: *** [CMakeFiles/CMakeProject-build.dir/build.make:93: CMakeProject-build-prefix/src/CMakeProject-build-stamp/CMakeProject-build-configure] エラー 1
                        gmake[1]: *** [CMakeFiles/Makefile2:125: CMakeFiles/CMakeProject-build.dir/all] エラー 2
                        gmake: *** [Makefile:136: all] エラー 2
      
                        *** CMake build failed
                        [end of output]
      
                    note: This error originates from a subprocess, and is likely not a problem with pip.
                    ERROR: Failed building wheel for cmake
                  Failed to build cmake
                  ERROR: Could not build wheels for cmake, which is required to install pyproject.toml-based projects
                  [end of output]
      
              note: This error originates from a subprocess, and is likely not a problem with pip.
            error: subprocess-exited-with-error
      
            × pip subprocess to install backend dependencies did not run successfully.
            │ exit code: 1
            ╰─> See above for output.
      
            note: This error originates from a subprocess, and is likely not a problem with pip.
            [end of output]
      
        note: This error originates from a subprocess, and is likely not a problem with pip.
      error: subprocess-exited-with-error
      
      × pip subprocess to install backend dependencies did not run successfully.
      │ exit code: 1
      ╰─> See above for output.
      
      note: This error originates from a subprocess, and is likely not a problem with pip.
      [end of output]
  
  note: This error originates from a subprocess, and is likely not a problem with pip.
error: subprocess-exited-with-error

× pip subprocess to install build dependencies did not run successfully.
│ exit code: 1
╰─> See above for output.

note: This error originates from a subprocess, and is likely not a problem with pip.
strnh@ghostbsd ~ [1]> sudo pkg install www/py-streamlit
パスワード: 
Updating FreeBSD repository catalogue...
FreeBSD repository is up to date.
Updating GhostBSD repository catalogue...
GhostBSD repository is up to date.
Updating GhostBSD-base repository catalogue...
GhostBSD-base repository is up to date.
All repositories are up to date.
The following 37 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
	arrow: 19.0.1_1 [GhostBSD]
	aws-c-s3: 0.7.11 [GhostBSD]
	aws-crt-cpp: 0.31.0 [GhostBSD]
	aws-sdk-cpp: 1.11.498 [GhostBSD]
	benchmark: 1.9.1,1 [FreeBSD]
	fam: 2.6.10_10 [GhostBSD]
	grpc: 1.70.1_1,2 [GhostBSD]
	libimagequant: 4.3.4_1 [FreeBSD]
	libraqm: 0.10.2 [GhostBSD]
	llvm19-lite: 19.1.7_1 [GhostBSD]
	mDNSResponder: 2200.140.11 [GhostBSD]
	mozjpeg: 4.1.5 [FreeBSD]
	opentelemetry-cpp: 1.19.0 [FreeBSD]
	pkg-devel: 2.0.99.5 [GhostBSD]
	py311-altair: 5.5.0 [FreeBSD]
	py311-jsonschema: 4.23.0 [FreeBSD]
	py311-jsonschema-specifications: 2024.10.1 [FreeBSD]
	py311-markdown-it-py: 3.0.0 [FreeBSD]
	py311-mdurl: 0.1.2_2 [FreeBSD]
	py311-narwhals: 1.27.1 [FreeBSD]
	py311-olefile: 0.46_1 [FreeBSD]
	py311-pillow: 11.0.0 [FreeBSD]
	py311-protobuf: 5.29.3,1 [FreeBSD]
	py311-pyarrow: 19.0.1 [FreeBSD]
	py311-referencing: 0.36.2 [FreeBSD]
	py311-rich: 13.9.4 [FreeBSD]
	py311-rpds-py: 0.13.2_12 [FreeBSD]
	py311-streamlit: 1.42.2 [FreeBSD]
	py311-tenacity: 9.0.0 [FreeBSD]
	py311-tkinter: 3.11.11_9 [FreeBSD]
	py311-toml: 0.10.2_1 [FreeBSD]
	py311-tornado: 6.4 [FreeBSD]
	sqlite3-tcl: 3.46.1_1,1 [GhostBSD]
	talloc242: 2.4.2_1 [FreeBSD]
	tdb1410: 1.4.10_1,1 [FreeBSD]
	tevent016: 0.16.1_1 [GhostBSD]
	tk86: 8.6.16 [GhostBSD]

Number of packages to be installed: 37

The process will require 1 GiB more space.
118 MiB to be downloaded.

Proceed with this action? [y/N]: y
[1/28] Fetching py311-toml-0.10.2_1.pkg: 100%   42 KiB  43.1kB/s    00:01    
[2/28] Fetching py311-tornado-6.4.pkg: 100%  846 KiB 866.4kB/s    00:01    
[3/28] Fetching aws-sdk-cpp-1.11.498.pkg: 100%   83 MiB   2.5MB/s    00:35    
[4/28] Fetching libimagequant-4.3.4_1.pkg: 100%  462 KiB 473.0kB/s    00:01    
[5/28] Fetching py311-jsonschema-specifications-2024.10.1.pkg: 100%   12 KiB  12.1kB/s    00:01    
[6/28] Fetching tk86-8.6.16.pkg: 100%    2 MiB   2.0MB/s    00:01    
[7/28] Fetching aws-c-s3-0.7.11.pkg: 100%   95 KiB  97.3kB/s    00:01    
[8/28] Fetching py311-referencing-0.36.2.pkg: 100%   68 KiB  69.3kB/s    00:01    
[9/28] Fetching py311-streamlit-1.42.2.pkg: 100%    8 MiB   2.9MB/s    00:03    
[10/28] Fetching arrow-19.0.1_1.pkg: 100%    9 MiB   2.3MB/s    00:04    ^[[B
[11/28] Fetching py311-markdown-it-py-3.0.0.pkg: 100%  140 KiB 143.4kB/s    00:01    
[12/28] Fetching py311-altair-5.5.0.pkg: 100%  512 KiB 524.1kB/s    00:01    
[13/28] Fetching py311-jsonschema-4.23.0.pkg: 100%  189 KiB 193.6kB/s    00:01    
[14/28] Fetching benchmark-1.9.1,1.pkg: 100%  138 KiB 141.7kB/s    00:01    
[15/28] Fetching py311-rpds-py-0.13.2_12.pkg: 100%  246 KiB 251.8kB/s    00:01    
[16/28] Fetching py311-narwhals-1.27.1.pkg: 100%  516 KiB 528.0kB/s    00:01    
[17/28] Fetching py311-olefile-0.46_1.pkg: 100%   57 KiB  58.3kB/s    00:01    
[18/28] Fetching py311-mdurl-0.1.2_2.pkg: 100%   17 KiB  17.5kB/s    00:01    
[19/28] Fetching py311-pillow-11.0.0.pkg: 100%  865 KiB 886.1kB/s    00:01    
[20/28] Fetching aws-crt-cpp-0.31.0.pkg: 100%  220 KiB 225.0kB/s    00:01    
[21/28] Fetching py311-protobuf-5.29.3,1.pkg: 100%  445 KiB 456.2kB/s    00:01    
[22/28] Fetching py311-tkinter-3.11.11_9.pkg: 100%   21 KiB  21.3kB/s    00:01    
[23/28] Fetching grpc-1.70.1_1,2.pkg: 100%    5 MiB   2.6MB/s    00:02    
[24/28] Fetching libraqm-0.10.2.pkg: 100%   33 KiB  33.7kB/s    00:01    
[25/28] Fetching py311-rich-13.9.4.pkg: 100%  529 KiB 541.3kB/s    00:01    
[26/28] Fetching py311-tenacity-9.0.0.pkg: 100%   48 KiB  49.0kB/s    00:01    
[27/28] Fetching opentelemetry-cpp-1.19.0.pkg: 100%  510 KiB 521.8kB/s    00:01    
[28/28] Fetching py311-pyarrow-19.0.1.pkg: 100%    5 MiB   2.5MB/s    00:02    
Checking integrity... done (19 conflicting)
  - mDNSResponder-2200.140.11 [GhostBSD] conflicts with avahi-libdns-0.8_2 [installed] on /usr/local/lib/libdns_sd.so
  - mDNSResponder-2200.140.11 [FreeBSD] conflicts with avahi-libdns-0.8_2 [installed] on /usr/local/lib/libdns_sd.so
  - tevent016-0.16.1_1 [GhostBSD] conflicts with tevent-0.15.0 [installed] on /usr/local/include/tevent.h
  - tdb1410-1.4.10_1,1 [FreeBSD] conflicts with tdb-1.4.9,1 [installed] on /usr/local/bin/tdbbackup
  - tdb1410-1.4.10_1,1 [GhostBSD] conflicts with tdb-1.4.9,1 [installed] on /usr/local/bin/tdbbackup
  - sqlite3-tcl-3.46.1_1,1 [GhostBSD] conflicts with sqlite3-3.46.1_1,1 [installed] on /usr/local/bin/sqlite3
  - sqlite3-tcl-3.46.1_1,1 [GhostBSD] conflicts with sqlite3-3.46.1_1,1 [GhostBSD] on /usr/local/bin/sqlite3
  - mozjpeg-4.1.5 [FreeBSD] conflicts with jpeg-turbo-3.1.0 [installed] on /usr/local/bin/cjpeg
  - mozjpeg-4.1.5 [FreeBSD] conflicts with jpeg-turbo-3.1.0 [GhostBSD] on /usr/local/bin/cjpeg
  - mozjpeg-4.1.5 [GhostBSD] conflicts with jpeg-turbo-3.1.0 [installed] on /usr/local/bin/cjpeg
  - talloc242-2.4.2_1 [FreeBSD] conflicts with talloc-2.4.1 [installed] on /usr/local/include/pytalloc.h
  - talloc242-2.4.2_1 [GhostBSD] conflicts with talloc-2.4.1 [installed] on /usr/local/include/pytalloc.h
  - fam-2.6.10_10 [GhostBSD] conflicts with gamin-0.1.10_10 [installed] on /usr/local/include/fam.h
  - fam-2.6.10_10 [GhostBSD] conflicts with gamin-0.1.10_10 [FreeBSD] on /usr/local/include/fam.h
  - pkg-devel-2.0.99.5 [GhostBSD] conflicts with pkg-2.0.6 [installed] on /usr/local/etc/bash_completion.d/_pkg.bash
  - pkg-devel-2.0.99.5 [GhostBSD] conflicts with pkg-1.21.3 [GhostBSD] on /usr/local/etc/bash_completion.d/_pkg.bash
  - pkg-devel-2.0.99.5 [GhostBSD] conflicts with pkg-2.0.6 [FreeBSD] on /usr/local/etc/bash_completion.d/_pkg.bash
  - llvm19-lite-19.1.7_1 [GhostBSD] conflicts with llvm19-19.1.7_1 [installed] on /usr/local/llvm19/lib/clang/19/include/arm_bf16.h
  - llvm19-lite-19.1.7_1 [GhostBSD] conflicts with llvm19-19.1.7_1 [GhostBSD] on /usr/local/llvm19/lib/clang/19/include/arm_bf16.h
Checking integrity... done (0 conflicting)
Conflicts with the existing packages have been found.
One more solver iteration is needed to resolve them.
The following 28 package(s) will be affected (of 0 checked):

New packages to be INSTALLED:
	arrow: 19.0.1_1 [GhostBSD]
	aws-c-s3: 0.7.11 [GhostBSD]
	aws-crt-cpp: 0.31.0 [GhostBSD]
	aws-sdk-cpp: 1.11.498 [GhostBSD]
	benchmark: 1.9.1,1 [FreeBSD]
	grpc: 1.70.1_1,2 [GhostBSD]
	libimagequant: 4.3.4_1 [FreeBSD]
	libraqm: 0.10.2 [GhostBSD]
	opentelemetry-cpp: 1.19.0 [FreeBSD]
	py311-altair: 5.5.0 [FreeBSD]
	py311-jsonschema: 4.23.0 [FreeBSD]
	py311-jsonschema-specifications: 2024.10.1 [FreeBSD]
	py311-markdown-it-py: 3.0.0 [FreeBSD]
	py311-mdurl: 0.1.2_2 [FreeBSD]
	py311-narwhals: 1.27.1 [FreeBSD]
	py311-olefile: 0.46_1 [FreeBSD]
	py311-pillow: 11.0.0 [FreeBSD]
	py311-protobuf: 5.29.3,1 [FreeBSD]
	py311-pyarrow: 19.0.1 [FreeBSD]
	py311-referencing: 0.36.2 [FreeBSD]
	py311-rich: 13.9.4 [FreeBSD]
	py311-rpds-py: 0.13.2_12 [FreeBSD]
	py311-streamlit: 1.42.2 [FreeBSD]
	py311-tenacity: 9.0.0 [FreeBSD]
	py311-tkinter: 3.11.11_9 [FreeBSD]
	py311-toml: 0.10.2_1 [FreeBSD]
	py311-tornado: 6.4 [FreeBSD]
	tk86: 8.6.16 [GhostBSD]

Number of packages to be installed: 28

The process will require 971 MiB more space.

Proceed with this action? [y/N]:y
Message from libimagequant-4.3.4_1:

--
===>   NOTICE:

The libimagequant port currently does not have a maintainer. As a result, it is
more likely to have unresolved issues, not be up-to-date, or even be removed in
the future. To volunteer to maintain this port, please create an issue at:

https://bugs.freebsd.org/bugzilla

More information about port maintainership is available at:

https://docs.freebsd.org/en/articles/contributing/#ports-contributing

pip で入れようとする = コンパイル(..うまく行かない)
pkg でいれると足りない(なぜ!?)

streamlit 1.42.2 requires cachetools<6,>=4.0, which is not installed.
streamlit 1.42.2 requires pydeck<1,>=0.8.0b4, which is not installed.

まだ足りないようです。

$ pip install cachetools
$ pip install pydeck
$ pip install blinker
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: blinker in /home/hiko/.local/lib/python3.11/site-packages (1.9.0)
$ streamlit run ./app2.py

      👋 Welcome to Streamlit!

      If you’d like to receive helpful onboarding emails, news, offers, promotions,
      and the occasional swag, please enter your email address below. Otherwise,
      leave this field blank.

      Email:  strnh@*****.com

  You can find our privacy policy at https://streamlit.io/privacy-policy

  Summary:
  - This open source library collects usage statistics.
  - We cannot see and do not store information contained inside Streamlit apps,
    such as text, charts, images, etc.
  - Telemetry data is stored in servers in the United States.
  - If you'd like to opt out, add the following to ~/.streamlit/config.toml,
    creating that file if necessary:

    [browser]
    gatherUsageStats = false


  You can now view your Streamlit app in your browser.

  Local URL: http://localhost:8501
  Network URL: http://192.168.0.1:8501

ようやく動いてくれました・・・

テスト完了・・・

サンプル見た感じ、コレでちょっとしたものはすぐに作れます。素晴らしい。
スクリーンショット

みなさんもお試しあれ。

Discussion