LoginSignup
1
0

More than 1 year has passed since last update.

Windows上で、Atcoderのローカルテスタを使ってPythonプログラムを実行する際につまずいたことメモ

Last updated at Posted at 2023-02-24

Atcoder Heuristic Contest(AHC)のローカル版テスタを使った際にちょっとつまずいたので覚書として残しておく。

問題

OSはWindows10を使用。Python3とRustがすでにインストールされている状態。
Atcoderのコンテストサイトからツール:「ローカル版」をダウンロード・展開し任意の場所に移す。「サンプルコード(C++,Python)」もダウンロード・展開し、先ほどの「ローカル版」のtoolsフォルダ内にsample_submission.pyをコピー&ペーストしておく。

サンプルコードをテストしようと思い、コマンドプロンプトへ
cargo run --release --bin tester python3 sample_submission.py < ./in/0000.txt > out.txt
と打って実行した。
 その結果、パーミッションエラーが返ってきた。

スクリーンショット 2023-02-25 090824.png

Python Your program has terminated unexpectedly
thread 'main' panicked at 'called Result::unwrap() on an Err value: Os { code: 5, kind: PermissionDenied, message: "アクセスが拒否されました。" }', src\bin\tester.rs:97:22

こうしたら動いた

python3PY へ変える。

つまり、以下のようなコマンドにする。
cargo run --release --bin tester PY sample_submission.py < ./in/0000.txt > out.txt

Powershell(VSCodeのターミナル含む)上で動かす場合は、

cat ./in/0000.txt | cargo run --release --bin tester PY sample_submission.py > out.txt

実行するPythonのバージョンを指定したいときはフルパスを入れる。

cargo run --release --bin tester (自分でインストールしたpython.exeのフルパス) sample_submission.py < ./in/0000.txt > out.txt

なぜ動いたか

「Powershellのgcm python3コマンドが教えてくれるフルパス」=「普段使っているpythonの実行ファイルのフルパス」だと思いこんでいた。

設定を特に触っていない限りpython3コマンドで呼び出されるのは、Windowsにデフォルトで入っているpython3.exeである。python3.exeがいる場所はPowershell上でgcm python3と入れることで分かる。クリックしてみるとわかるが、このpython3.exe、MicrosoftストアにつながるだけでPythonプログラムを動かす機能は無い。これがパーミッションエラーと返ってきていた原因のようだ。対して、PYというコマンドではパイソンランチャーが起動しインストールされている中から適切なバージョンが選んで実行される。

参考

1
0
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
1
0