@creative-account

Are you sure you want to delete the question?

Leaving a resolved question undeleted may help others!

Python + Electronでデスクトップアプリの作成

実現したいこと

Pythonは通常、CUIで動作するプログラムを作成するための言語です。しかし、Flaskというフレームワークを使うことで、PythonプログラムにElectronを使ってGUIを追加できると聞きました。

また、Pythonの実行環境がインストールされていないPCにPythonプログラムを配布する際には、PyInstallerを使用して実行ファイルに変換できるとも聞いています。

そこで、Python + Flask + Electronで作成したアプリを、PythonやNode.jsがインストールされていないPCで動作させることは可能でしょうか? 実行ファイル化したPythonプログラムとElectronが連携する仕組みについて、どなたかご教示いただけると助かります。

0 likes

4Answer

ググった感じだと、node.js は必須の気がします。
Electron が node.js を前提としている様です。

python + GUI で浮かぶ構成としては、python + tcl/tk (tkinter) があります。
他にもあるとは思いますが、ご参考まで。

0Like

Python + Electronでデスクトップアプリの作成

やりたい事は何でしょうか?

しかし、Flaskというフレームワークを使うことで、PythonプログラムにElectronを使ってGUIを追加できると聞きました。

ソースを提示いただくことで回答が付きやすくなるかと思います。
一般的にはFlaskはウェブアプリケーションフレームワークとして使われると思います。

また、Pythonの実行環境がインストールされていないPCにPythonプログラムを配布する際には、PyInstallerを使用して実行ファイルに変換できるとも聞いています。

Flaskアプリケーションを実行ファイル化できるようですが、それはいわゆる「デスクトップアプリ」とは別物ではないでしょうか?
https://irokazari.com/python-flask-pc-web-app-implementation-pyinstaller-beginner/

【追記】
下記の方が質問者さんのやりたい事(Python + Electron)をやっているようですが、それなりに難しそうです。
https://qiita.com/tetutaro/items/ac04b4dca12fbbaf55dc
但し、試した環境はMacのようですが。

PythonやNode.jsがインストールされていないPCで動作させることは可能でしょうか?

ウェブアプリケーションではなくデスクトップアプリケーションに拘る理由は何でしょうか?

0Like

Comments

  1. オフラインで使用するアプリケーションなら「デスクトップアプリ」と呼んでも良いのかもしれません。ただ質問者さんは「PythonプログラムにElectronを使ってGUIを追加」したいとのことです。

  2. Hey, I’ve messed around with a similar setup before, so here’s what worked for me as a regular forum member (not an admin):

    Yes, it is possible to run a desktop app built with Python + Flask + Electron on a PC that doesn’t have Python or Node.js installed — but the important part is how you package everything together.

    Here’s the general idea:

    1. Python backend (Flask):
      Your Flask app can act like a local web server that Electron talks to. During development, Electron opens a browser window pointing to where Flask is running.

    2. Packaging Python with PyInstaller:
      PyInstaller can bundle your Python code and the Python interpreter into a single executable (or a folder with dependencies). That means the target PC doesn’t need Python installed — the executable has everything it needs.

    3. Packaging the whole thing with Electron:
      Electron bundles your front-end (HTML/CSS/JS) and the Node runtime. Then you have 2 runtimes bundled:

    The Python runtime bundled by PyInstaller,
    The Node/Electron runtime.
    You need a “launcher” script in Electron that starts the bundled Flask executable first, waits until the server is ready, and then opens the Electron BrowserWindow.

    1. Final packaging:
      After you have:

    A standalone Flask exe (via PyInstaller), and

    Your Electron app folder,
    https://irokazari.com/bitlife
    You can use something like Electron Packager or Electron Builder to create a single installer for Windows/macOS/Linux. The installer includes both the Flask exe and the Electron app. When the user runs the app, they don’t need Python or Node installed — everything is included.

ただしPythonはPyInstallerでexe化し、Electronは別でビルドし、FlaskはAPIとしてexeと連携させる必要があります。
PythonやNodeなしでも動きますが、完全に個別パッケージ化が必要です。
https://irokazari.com/geometry dash meltdown/python-flask-pc-web-app-implementation-pyinstaller-beginner/

0Like

Your answer might help someone💌