mieki256's diary



2025/12/20() [n年前の日記]

#1 [python] Pythonスクリプトをexe化するアレコレを調べてた

Pythonスクリプトをexe化するアレコレを調べてた。

Codonについて :

Pythonスクリプトを高速化する Codon なるものがあるらしいと知って、そのあたりを調べてた。10倍から100倍の処理速度になるらしい。

しかし…。色々ググって調べてたんだけど…。Windows上では動作しないとのことで…。現状では Linux と Mac にしか対応してないらしい。Windows上で使いたいならWSL上で使えるよ、という解説記事しか見つからなかったけど、WSL上で動かすということは、Linux 上で動かしてるってことだよな…。

_Windows Support (2025) by K0lb3 - Pull Request #691 - exaloop/codon

Windowsに対応させるのは、なかなか大変らしい…。

Nuitkaについて :

PythonスクリプトをC言語のソースに変換して、Cコンパイラでビルドして exe化する Nuitka という仕組みもある。Windows11 x64 25H2 + Python 3.10.10 + Nuitka 2.8.9 で exe化できるか試していたのだけど、以前とオプションがちょっと変わってたのでメモ。

GUIアプリを作成したい時、以前は "--windows-disable-console" を指定していたのだけど…。このオプションをつけると作成したexeの実行時にコンソールウインドウ(DOS窓)は開かない。
python -m nuitka --standalone --enable-plugin=tk-inter --windows-disable-console --windows-icon-from-ico=icon.ico pyrgbfloatviewer.pyw

しかし、Nuitka 2.8.9 にアップデートしたら「--windows-console-mode=disable を使え」と警告が出てきた。
python -m nuitka --standalone --enable-plugin=tk-inter --windows-console-mode=disable --windows-icon-from-ico=icon.ico pyrgbfloatviewer.pyw

しかし、このオプションをつけると tkinter を使ったアプリが起動しない…。

どうやら --windows-console-mode=attach にしないとダメっぽい。また、--onefile をつけて1ファイル化しないと動いてくれなかった。
python -m nuitka --standalone --onefile --enable-plugin=tk-inter --windows-console-mode=attach --windows-icon-from-ico=icon.ico pyrgbfloatviewer.pyw

--windows-console-mode に指定できるのは4種類。

_Nuitka User Manual - Nuitka the Python Compiler
force : (Default) Forces a console window to open. If the program is launched from an existing console, that console will be re-used.

disable : Prevents a console window from opening. Use this for GUI programs that do not require console interaction.

attach : Attaches to an existing console if the program is launched from one; otherwise, no console window is created.

hide : Forces a console window to be created, but immediately minimizes it. The console window will typically flash briefly.

  • force : コンソールウィンドウを強制的に開く。
  • disable : コンソールウィンドウを開かない。
  • attach : コンソールから起動された場合は既存のコンソールに接続する。そうでない場合はコンソールウィンドウを開かない。
  • hide : コンソールウィンドウを開くが直ちに最小化する。

  • ちなみに他のオプションの意味は以下。
  • --onefile : 1ファイル化する。
  • --enable-plugin=tk-inter : tkinter を使う時は指定する。
  • --windows-icon-from-ico=icon.ico : アイコンファイルを指定する。

Mojoについて :

Pythonではなくて別の言語になってしまうけれど、Mojoというプログラミング言語があるらしい。Pythonに近い書き方ができて、圧倒的に処理速度が速いのだとか。

これもWindows版は無かった…。Linux か Mac でしか動かないっぽい。しかもオープンソースじゃないらしい。

以上、1 日分です。

過去ログ表示

Prev - 2025/12 -
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31

カテゴリで表示

検索機能は Namazu for hns で提供されています。(詳細指定/ヘルプ


注意: 現在使用の日記自動生成システムは Version 2.19.6 です。
公開されている日記自動生成システムは Version 2.19.5 です。

Powered by hns-2.19.6, HyperNikkiSystem Project