質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.39%
GCC

GCCはGNU Compiler Collectionの略です。LinuxのC言語コンパイラのデファクトスタンダードであり、数多くの他言語やプラットフォームサポートもします。

MinGW

MinGW(ミン・ジー・ダブリュー)は GNUツールチェーンのWindows移植版です。 ランタイムライブラリと開発ツールで構成されています。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

Q&A

解決済

2回答

541閲覧

MingW64のgccを使いnuitkaでexeファイルを作成するのにwindows.hが見つからない

nezukichi

総合スコア13

GCC

GCCはGNU Compiler Collectionの略です。LinuxのC言語コンパイラのデファクトスタンダードであり、数多くの他言語やプラットフォームサポートもします。

MinGW

MinGW(ミン・ジー・ダブリュー)は GNUツールチェーンのWindows移植版です。 ランタイムライブラリと開発ツールで構成されています。

Python

Pythonは、コードの読みやすさが特徴的なプログラミング言語の1つです。 強い型付け、動的型付けに対応しており、後方互換性がないバージョン2系とバージョン3系が使用されています。 商用製品の開発にも無料で使用でき、OSだけでなく仮想環境にも対応。Unicodeによる文字列操作をサポートしているため、日本語処理も標準で可能です。

0グッド

0クリップ

投稿2024/10/04 06:27

編集2024/10/06 03:29

実現したいこと

Windows10でPython(tkinter使用)のプログラムをnuitkaでexeファイルを作成しようとしています。
CコンパイラはMingW64に含まれるgccです。

発生している問題・分からないこと

ビルド中にwindows.hとio.hが見つからず、コンパイルが止まってしまいます。

エラーメッセージ

error

1Nuitka-Scons: Backend C compiler: gcc (gcc 13.2.0). 2In file included from module.__main__.c:19: 3C:\050_VENV\010_WH~1\whisper\Lib\SITE-P~1\nuitka\build\include/nuitka/prelude.h:13:10: fatal error: windows.h: No such file or directory 4 13 | #include <windows.h> 5 | ^~~~~~~~~~~ 6compilation terminated. 7 8scons: *** [module.__main__.o] Error 1 9In file included from C:\PROGRA~1\WindowsApps\PYTHON~1.0_X\include/Python.h:8, 10 from __loader.c:4: 11C:\PROGRA~1\WindowsApps\PYTHON~1.0_X\include/pyconfig.h:59:10: fatal error: io.h: No such file or directory 12 59 | #include <io.h> 13 | ^~~~~~ 14compilation terminated. 15 16scons: *** [__loader.o] Error 1 17In file included from __constants.c:2: 18C:\050_VENV\010_WH~1\whisper\Lib\SITE-P~1\nuitka\build\include/nuitka/prelude.h:13:10: fatal error: windows.h: No such file or directory 19 13 | #include <windows.h> 20 | ^~~~~~~~~~~ 21compilation terminated. 22 23In file included from __helpers.c:4: 24C:\050_VENV\010_WH~1\whisper\Lib\SITE-P~1\nuitka\build\include/nuitka/prelude.h:13:10: fatal error: windows.h: No such file or directory 25 13 | #include <windows.h> 26 | ^~~~~~~~~~~ 27compilation terminated. 28 29scons: *** [__constants.o] Error 1 30scons: *** [__helpers.o] Error 1 31FATAL: Failed unexpectedly in Scons C backend compilation.

該当のソースコード

Python

1import tkinter as tk 2 3from tkinter import ttk 4 5from tkinter import filedialog 6 7import threading 8 9import whisper 10 11 12# メインウインドウ 13root = tk.Tk() 14root.title("OpenAI 文字起こし") 15root.geometry="700x80" 16 17# 変換精度選択 18# StringVar()を使って選択されたコンボボックスの値を保持 19lb_var = tk.StringVar() 20 21# 入出力ファイル名の管理用変数 22file_path_input = tk.StringVar() 23file_path_input.set("音声ファイル名") 24file_path_output = tk.StringVar() 25file_path_output.set("テキストファイル名") 26 27def open_input_file_dialog(): 28 # 音声ファイル選択ダイアログを表示 29 txt_path_input = filedialog.askopenfilename( 30 title = '音声ファイルを選択', 31 filetypes=[("MP3ファイル", "*.mp3")] 32 ) 33 34 if txt_path_input: 35 file_path_input.set(txt_path_input) 36 37def open_output_file_dialog(): 38 # テキストファイル選択ダイアログを表示 39 txt_path_output = filedialog.asksaveasfilename( 40 title = 'テキストファイルを選択', 41 filetypes=[("テキストファイル", "*.txt")] 42 ) 43 if txt_path_output != "" and txt_path_output[-4:] != '.txt': 44 txt_path_output += '.txt' 45 46 if txt_path_output: 47 file_path_output.set(txt_path_output) 48 49def start_thread(): 50 threading.Thread(target=start_translation, daemon=True).start() 51 52def start_translation(): 53 if file_path_input.get()!="音声ファイル名" and file_path_output.get()!="テキストファイル名": 54 btn_translation.config(text="変換中") 55 btn_translation.config(state="disabled") 56 root.update_idletasks 57 # 音声→テキスト変換開始 58 lb_idx = lb.curselection() 59 model = whisper.load_model(lb.get(lb_idx)) 60 result = model.transcribe(file_path_input.get()) 61 f = open(file_path_output.get() , 'w') 62 f.write(result["text"]) 63 f.close() 64 btn_translation.config(text="変換開始") 65 btn_translation.config(state="!disabled") 66 root.after(0) 67 68# 音声ファイル名表示用テキストボックス 69text_box_input = ttk.Entry(root, width=30, textvariable=file_path_input) 70text_box_input.grid(row=0, column=0, padx = 5, pady=10) 71text_box_input.config(state="disabled") 72 73# テキストファイル名表示用テキストボックス 74text_box_output = ttk.Entry(root, width=30, textvariable=file_path_output) 75text_box_output.grid(row=1, column=0, padx=5, pady=10) 76text_box_output.config(state="disabled") 77 78 79# 音声ファイル選択(読み込み用)ファイルダイアログ表示ボタン 80btn_input = ttk.Button(root, text="音声ファイルを選択する", command=open_input_file_dialog) 81btn_input.grid(row=0, column=1, padx=5, pady=10) 82 83# テキストファイル選択(新規ファイル作成用)ファイルダイアログ表示ボタン 84btn_output = ttk.Button(root,text="テキストファイルを選択する",command=open_output_file_dialog) 85btn_output.grid(row=1, column=1, padx=5, pady=10) 86 87# リストボックス用ラベル 88label = ttk.Label(root, text="       変換精度を選択") 89label.grid(row=2, column=0, padx=5, pady=10) 90 91# リストボックスの作成 92item_list = ["tiny", "base", "small", "medium", "large", "large-v3"] 93list_var = tk.StringVar(root, value=item_list) 94lb = tk.Listbox(root, listvariable=list_var) 95lb.select_set(3) # デフォルトの値 96lb.grid(row=2, column=1, padx=5, pady=10) 97 98 99# 変換開始ボタン 100btn_translation = ttk.Button(root, text="変換開始", command=start_thread) 101btn_translation.grid(row=3, column=0, padx=5, pady=10) 102 103# 終了ボタン 104btn_exit = ttk.Button(root,text="終了", command=root.destroy) 105btn_exit.grid(row=3, column=2, padx=5,pady=10) 106 107root.mainloop() 108

試したこと・調べたこと

  • teratailやGoogle等で検索した
  • ソースコードを自分なりに変更した
  • 知人に聞いた
  • その他
上記の詳細・結果

teratailでnuitka windows.hと調べましたが引っ掛かりませんでした。
また、googleでも検索しましたが、該当する問題は見つかりませんでした。

補足

Visual Studioをインストールして使うといった方法は見かけましたが、PCのスペックの問題等でできればgccを使いたいと思っています。
gccを使う場合に別途開発環境を整える必要があるのでしょうか?

[追記]
ArtyさんのようにMSYSを入れてpacman or pipでgccなど各種パッケージをインストールしていきました。
しかし、nuitkaをpipでインストールしようとすると
src/c/_cffi_backend.c:15:10: fatal error: ffi.h: No such file or directory
15 | #include <ffi.h>
| ^~~~~~~
compilation terminated.
error: command '/usr/bin/gcc' failed with exit code 1
となりインストールに失敗します。
ここまで来たのですが、今まで調べた限りMSYSでここまで必要という記述がなかったように思います。

もともとはnuitkaを実行する時に自動でダウンロードされるgccを使っていました。

インストールからgccのインストールまでは以下のようになっています。

(whisper) PS E:\Python_Env\whisper_local> pip install nuitka
Collecting nuitka
Using cached Nuitka-2.4.8-cp312-cp312-win_amd64.whl
Requirement already satisfied: ordered-set>=4.1.0 in e:\python_env\whisper\lib\site-packages (from nuitka) (4.1.0)
Requirement already satisfied: zstandard>=0.15 in e:\python_env\whisper\lib\site-packages (from nuitka) (0.23.0)
Installing collected packages: nuitka
Successfully installed nuitka-2.4.8

その次に(whisper_Tk.pyがソースファイルです)

python -m nuitka --mingw64 whisper_Tk.py

と行うと

Nuitka-Options: Used command line options: --mingw64 whisper_Tk.py
Nuitka-Options:WARNING: You did not specify to follow or include anything but main program. Check options and make sure
Nuitka-Options:WARNING: that is intended.
Nuitka: Starting Python compilation with Nuitka '2.4.8' on Python '3.12' commercial grade 'not installed'.
Nuitka: Completed Python level compilation and optimization.
Nuitka: Generating source code for C backend compiler.
Nuitka: Running data composer tool for optimal constant value handling.
Nuitka: Running C compilation via Scons.
Nuitka will use gcc from MinGW64 of winlibs to compile on Windows.

Is it OK to download and put it in 'C:\Users(ユーザ名)
AppData\Local\Packages\PYTHON1.12_\LOCALC1\Local\Nuitka\Nuitka\Cache\DOWNLO~1\gcc\x86_64\13.2.0-16.0.6-11.0.1-msvcrt-r1'.

Fully automatic, cached. Proceed and download? [Yes]/No : y
Nuitka: Downloading
Nuitka: 'https://github.com/brechtsanders/winlibs_mingw/releases/download/13.2.0-16.0.6-11.0.1-msvcrt-r1/winlibs-x86_64-posix-seh-gcc-13.2.0-llvm-16.0.6-mingw-w64msvcrt-11.0.1-r1.zip'.
Nuitka: Extracting to
Nuitka: 'C:\Users\kumap\AppData\Local\Packages\PYTHON1.12_\LOCALC1\Local\Nuitka\Nuitka\Cache\DOWNLO~1\gcc\x86_64\13.2.0-16.0.6-11.0.1-msvcrt-r1\mingw64\bin\gcc.exe'
Nuitka-Scons: Backend C compiler: gcc (gcc 13.2.0).
Nuitka-Scons: Backend linking program with 6 files (no progress information available for this stage).

と表示され、その後最初に投稿したエラーメッセージ(E:\Python_Env\whisper\Lib\site-packages\nuitka\build\include/nuitka/prelude.h:13:10: fatal error: windows.h: No such file or directory)が表示され、コンパイルが止まります。

hiroki-oさんの場合はこれで実行ファイルができたそうですので、どこが問題かわかりかねています。

バージョンはWindows11,Python 3.12.7,nuitka 2.4.8,
gcc.exe (MinGW-W64 x86_64-msvcrt-posix-seh, built by Brecht Sanders) 13.2.0
です。

他に必要な情報があればお知らせします。
よろしくお願い致します。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

toge_

2024/10/04 10:13

MinGW64はどうやってインストールされていますか?
nezukichi

2024/10/06 02:28

コメントありがとうございます。MSYSを試しましたがまだ解決できていません。 試した結果を質問に追記しました。
bsdfan

2024/10/06 12:00

間違ったINCLUDE_PATH系の環境変数を設定してたりしないですか?
nezukichi

2024/10/08 06:19

コメントありがとうございます。 INCLUDE_PATHですが特に設定していません。 Windowsの環境でも設定が必要でしょうか? In file included from C:\PROGRA~1\WindowsApps\PYTHON~1.0_X\include/Python.h から呼び出しているio.hが見つからない。 \whisper\Lib\SITE-P~1\nuitka\build\include/nuitka/prelude.h から呼び出しているwindows.hが見つからない。 確かにnuitkaがgccがないときにダウンロードしてくる winlibs-x86_64-posix-seh-gcc-13.2.0-llvm-16.0.6-mingw-w64msvcrt-11.0.1-r1.zip にはio.hもwindows.hも含まれていません。 こういった場合INCLUDE_PATHをどのように設定するがよいのでしょうか? 参考サイト等があれば教えていただけますでしょうか?
bsdfan

2024/10/08 06:50

winlibs-x86_64-posix-seh-gcc-13.2.0-llvm-16.0.6-mingw-w64msvcrt-11.0.1-r1.zip には、windows.h も io.h も含まれていますよ。(mingw64/x86_64-w64-mingw32/include の下) 念のため確認してみてください。(もしかするとダウンロードに失敗しているのかもしれません) ログを見ると、gccはそのダウンロードされたものが使われているようなので、悪さをしているとしたら環境変数かなとおもって質問しました。いま特に設定していないなら、nuitka用で環境変数を設定しないといけないとかはないと思います。
nezukichi

2024/10/09 06:44

たびたびのコメントありがとうございます。 確かに AppData\Local\Nuitka\Nuitka\Cache\downloads\gcc\x86_64\13.2.0-16.0.6-11.0.1-msvcrt-r1\mingw64\x86_64-w64-mingw32\include の下に両方のファイルがありました。(mingw64の直下のincludeしか見ていませんでした。) そこでまた疑問なのですが、そこにファイルが存在するのに見に行ってくれないのはなぜでしょうか? 職場のPCがしょぼすぎていったんnuitkaでビルドを始めると結果が出るまで2時間くらい平気でかかるのでなかなか検証が進みません。 自宅のPCでもう少し詳しく挙動を確認したいと思います。
nezukichi

2024/10/11 02:43

これが正解なのかわかりませんが、とりあえずビルドが成功したのでご報告します。 今までMicrosoft StoreからインストールしたPython 12を使っていましたが、それをアンインストールし、 https://www.Python.org/downloads/ からPython3.12.7をダウンロードし、インストールしました。 (カスタムインストールを選び、すべてのユーザ用、環境変数を加えるとしました。) その後、 > python -m nuitka --standalone --enable-plugin=tk-inter --module-parameter=numba-disable-jit=yes whisper.py とするとdistフォルダが作成されました。 ここまではよかったのですが次の問題が生じてしまいました。 distフォルダ中に作成されるwhisper_Tk.exeを実行すると whisper_Tk.dist\\whisper\\assets\\mel_filters.npz' がないといって止まってしまいます。 assetsフォルダにはmel_filters.npzとmultilingual.tiktokenの2つが必須となるようです。 (https://github.com/openai/whisper/tree/main/whisper/assetsからダウンロードして指定の位置に置くとエラーが発生せず実行できます) 最終的にはnuitkaに--onefileを付けてexeを作りたいのですが、上記の2つが含まれないため実行に失敗するみたいです。 どなたか、なぜ上記2つがdistに含まれないのか?どのように解決すればよいのかご教示いただけないでしょうか? よろしくお願いいたします。
bsdfan

2024/10/11 03:06 編集

ビルドできるようになってよかったです。 知らなかったですが、nuitka はマイクロソフトストアのpythonは非対応と書かれていますね。 https://nuitka.net/info/unsupported-windows-app-store-python.html 新しい質問については、コメントに書いてもあまり読まれませんし、当初から大きく変わってくるので、いったん本QAは書かれている内容で自己解決にして、別の質問をたてられたほうが良いと思います。
guest

回答2

0

Windows 11、Python 3.12.4、venvで確認しました。

以下の手順で問題無く実行ファイルが作成されて、文字起こしも正常にできています。
(ソースを仮にtest.pyとする)

python -m pip install openai-whisper python -m pip install nuitka python -m nuitka --mingw64 test.py

私の環境にもmingw64が入っているのですが、それは無視されてgccを別途ダウンロードされました。
ダウンロードされたファイルに、windows.hもio.hも入っています。
要するに、gccに関する事前設定は不要です。

Nuitka-Scons: Non downloaded winlibs-gcc 'c:\mingw64\bin\gcc.exe' is being ignored, Nuitka is very dependent on the Nuitka-Scons: precise one. Nuitka-Scons: Backend C compiler: gcc (gcc 13.2.0).

まずは、そのエラーメッセージの前までの出力を見て、どちらのgccが使用されているか切り分けてみてください。

それにしても、このプログラムは素晴らしいです!
皆さんも試してみてください。

投稿2024/10/05 12:01

hiroki-o

総合スコア956

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

nezukichi

2024/10/06 03:30

回答ありがとうございます。試してみましたが解決できませんでした。 試した結果は質問に追記してあります。 この場合どの辺りに原因がありそうでしょうか?
guest

0

自己解決

今までMicrosoft StoreからインストールしたPython 12を使っていましたが、それをアンインストールし、
https://www.Python.org/downloads/
からPython3.12.7をダウンロードし、インストールしました。
(カスタムインストールを選び、すべてのユーザ用、環境変数を加えるとしました。)

その後、

python -m nuitka --standalone --enable-plugin=tk-inter --module-parameter=numba-disable-jit=yes whisper.py

とするとdistフォルダが作成されました。

とりあえず当初のWindows.hとio.hが見つからないという問題はこれで解消しました。

投稿2024/10/11 04:57

nezukichi

総合スコア13

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.39%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問