atcoder-toolsでtestをしようとしたら、WinError 193が出てしまう
解決したいこと
atcoder-tools test
を実行したときに、エラーなしでmain.pyがきちんとテストされること。
<実行環境>
- Windows 11 (24H2)
- Python 3.11.4
- atcoder-tools 2.14.0
発生している問題・エラー
AtCoderの問題について、そのサンプルケースとmetadata.json
、および解答したmain.py
の入っているディレクトリで、以下のコマンドを実行しました:
atcoder-tools test
なお、main.py
の先頭にはshebangを入れています。
しかし、実行すると、以下のようなエラーが出ます。
長くなりますが、エラーメッセージ全文を載せます。
エラーメッセージ全文
2025-06-26 09:10:49,498 INFO: Inferred exec file: .\main.py
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "D:\User_Folder\学校\プログラミングコンテスト\AtCoder\.venv\Scripts\atcoder-tools.exe\__main__.py", line 7, in <module>
File "D:\user_folder\学校\プログラミングコンテスト\AtCoder\.venv\Lib\site-packages\atcodertools\atcoder_tools.py", line 66, in main
exit_program(tester_main(prog, args))
^^^^^^^^^^^^^^^^^^^^^^^
File "D:\user_folder\学校\プログラミングコンテスト\AtCoder\.venv\Lib\site-packages\atcodertools\tools\tester.py", line 429, in main
return run_all_tests(exec_file, in_sample_file_list, out_sample_file_list, args.timeout, args.knock_out,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\user_folder\学校\プログラミングコンテスト\AtCoder\.venv\Lib\site-packages\atcodertools\tools\tester.py", line 214, in run_all_tests
test_summary = run_for_samples(
^^^^^^^^^^^^^^^^
File "D:\user_folder\学校\プログラミングコンテスト\AtCoder\.venv\Lib\site-packages\atcodertools\tools\tester.py", line 121, in run_for_samples
exec_res = run_program(exec_file, in_sample_file,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "D:\user_folder\学校\プログラミングコンテスト\AtCoder\.venv\Lib\site-packages\atcodertools\executils\run_program.py", line 38, in run_program
proc = subprocess.run(
^^^^^^^^^^^^^^^
File "C:\Users\H.Yuto.hst\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 548, in run
with Popen(*popenargs, **kwargs) as process:
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\H.Yuto.hst\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 1026, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "C:\Users\H.Yuto.hst\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 1538, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
OSError: [WinError 193] %1 は有効な Win32 アプリケーションではありません。
該当するソースコード
問題の解答そのものを載せるのはよくないと考え、テンプレートを載せます。なお、元々atcoder-toolsに含まれるテンプレートのmain.py
でも、同様のエラーが出ました。
#!/usr/bin/env python3
import sys
YES = "Yes" # type: str
NO = "No" # type: str
def solve(S: str):
return
# Generated by 2.14.0 https://github.com/kyuridenamida/atcoder-tools (tips: You use the default template now. You can remove this line by using your custom template)
def main():
def iterate_tokens():
for line in sys.stdin:
for word in line.split():
yield word
tokens = iterate_tokens()
S = next(tokens) # type: str
solve(S)
if __name__ == '__main__':
main()
自分自身で、テストケースなどのファイルを自動的に移動して、そこでテストできるようにしています。
以下に、実際に構築しているディレクトリ構造を示します。
長くなるので、折りたたんでいます。
ディレクトリ構造(抜粋)
AtCoder
│ .atcodertools.toml
│ .atcodertools.toml.dump
│ .gitignore
│
├───.venv
│ │ (ここには仮想環境に関するファイル・フォルダ群)
│
├───answers
│ │ .gitignore
│ │
│ └───ABC
│ └───ABC350
│ ├───A
│ │ main.py
│ │
│ ├───B
│ │ main.py
│ │
│ ├───C
│ │ main.py
│ │
│ ├───D
│ │ main.py
│ │
│ ├───E
│ │ main.py
│ │
│ ├───F
│ │ main.py
│ │
│ └───G
│ main.py
│ (省略)
│
├───problems
│ │ .gitignore
│ │
│ └───ABC
│ └───ABC350
│ ├───A
│ │ in_1.txt
│ │ in_2.txt
│ │ in_3.txt
│ │ metadata.json
│ │ out_1.txt
│ │ out_2.txt
│ │ out_3.txt
│ │
│ ├───B
│ │ in_1.txt
│ │ in_2.txt
│ │ in_3.txt
│ │ metadata.json
│ │ out_1.txt
│ │ out_2.txt
│ │ out_3.txt
│ │
│ ├───C
│ │ in_1.txt
│ │ in_2.txt
│ │ in_3.txt
│ │ metadata.json
│ │ out_1.txt
│ │ out_2.txt
│ │ out_3.txt
│ │
│ ├───D
│ │ in_1.txt
│ │ in_2.txt
│ │ in_3.txt
│ │ metadata.json
│ │ out_1.txt
│ │ out_2.txt
│ │ out_3.txt
│ │
│ ├───E
│ │ in_1.txt
│ │ in_2.txt
│ │ in_3.txt
│ │ metadata.json
│ │ out_1.txt
│ │ out_2.txt
│ │ out_3.txt
│ │
│ ├───F
│ │ in_1.txt
│ │ in_2.txt
│ │ in_3.txt
│ │ in_4.txt
│ │ metadata.json
│ │ out_1.txt
│ │ out_2.txt
│ │ out_3.txt
│ │ out_4.txt
│ │
│ └───G
│ in_1.txt
│ in_2.txt
│ metadata.json
│ out_1.txt
│ out_2.txt
│ (省略)
│
├───scripts
│ │ archive_answer.py
│ │ automate_prepare_and_edit.py
│ │ generate_contest.py
│ │ metadata_generator.py
│ │ prepare_workspace.py
│ │ run_tests.py
│ │ submit_answer.py
│ │
│ └───__pycache__
│ metadata_generator.cpython-311.pyc
│ metadata_generator.cpython-313.pyc
│
├───src
│ └───template
│ metadata.json
│ teplate.py
│
├───task
│ ├───modify_cache
│ │ CacheModifier.py
│ │ usercache.cache
│ │
│ └───TomlGenerator
│ setToml.py
│
└───workspace
in_1.txt
in_2.txt
in_3.txt
main.py
metadata.json
out_1.txt
out_2.txt
out_3.txt
自分で試したこと
AtCoder
ディレクトリ直下のscripts
ディレクトリ内には、自分で作成した自動化スクリプトがあります。それぞれ、atcoder-tools gen
コマンドで自動的に作成されるディレクトリを改変して、コンテストのカテゴリ(ABC、AHCなど)ごとに対してフォルダにまとめたり、自動的に問題に関するin、outのファイル、metadata.json
、そしてmain.py
を、workspace
ディレクトリにコピーして、そのディレクトリに移動したり、といった機能を持っています。これらのスクリプトに問題はありません。
ただ、workspace
ディレクトリに移動した後、atcoder-tools test
を実行すると、
OSError: [WinError 193] %1 は有効な Win32 アプリケーションではありません。
というエラーが出ます。
ちなみに、shebangはLinux系ではにんしきされるが、Windowsでは無視されそうな気がします。私の環境では、shebangの有無にかかわらず、同様のエラーが出ました。
有識者の方、解決方法を伝授いただけると幸いです。