LoginSignup
2
1
Qiita×Findy記事投稿キャンペーン 「自分のエンジニアとしてのキャリアを振り返ろう!」

LinuxでPythonのGUI(tkinter)のWindows実行ファイルをクロスコンパイルする

Posted at

LinuxでPythonコーディングしてWindowsにexeファイルを提供する方法についてまとめる

Wineのインストール

インストール手順
https://wiki.winehq.org/Ubuntu

$ sudo dpkg --add-architecture i386
$ sudo mkdir -pm755 /etc/apt/keyrings
$ sudo wget -O /etc/apt/keyrings/winehq-archive.key https://dl.winehq.org/wine-builds/winehq.key
$ sudo wget -NP /etc/apt/sources.list.d/ https://dl.winehq.org/wine-builds/ubuntu/dists/jammy/winehq-jammy.sources
$ sudo apt update
$ sudo apt install --install-recommends winehq-stable

PythonをWineにインストール

ここでinstallerをダウンロード
https://www.python.org/downloads/windows/

インストールする。
ダウンロードディレクトリとinstallerファイル名は各自調整

$ wine ~/Downloads/python-3.12.1-amd64.exe

Python環境の整備

tkinterのインストール

$ wine ~/.wine/drive_c/users/`users`/Local\ Settings/Application\ Data/Programs/Python/Python312/python.exe -m pip install pytk

PyInstallerのインストール

$ wine ~/.wine/drive_c/users/`users`/Local\ Settings/Application\ Data/Programs/Python/Python312/python.exe -m pip install PyInstaller

GUIサンプル

gui.py

import tkinter

root = tkinter.Tk()
root.title("Sample")
root.geometry("400x400")
root.mainloop()

Windwos向けのexeファイル作成

$ wine ~/.wine/drive_c/users/`users`/Local\ Settings/Application\ Data/Programs/Python/Python312/python.exe -m PyInstaller gui.py --onefile --noconsole

exeファイル生成の確認

$ ls -l dist/
合計 10040
-rwxrwxr-x 1 noxon noxon 10277031  2月  3 20:01 gui.exe

Wineで実行

$ wine dist/gui.exe
2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1