首页 > 解决方案 > 在奥赛罗棋盘游戏中使用时,windows python 子进程将不起作用

问题描述

还在学习python,遇到了使用“AI”的棋盘游戏奥赛罗。[https://www.instructables.com/id/Othello-Artificial-Intelligence/][1] 游戏有两个版本 - 玩家对玩家和玩家对 AI。我遇到的问题是玩家与 AI,Othello_game.py。Othello_gui,播放器上的播放器可以正常工作。

错误是:

C:\Users\Joe\Documents\OthelloAI-master\OthelloAI-master> python othello_game.py [erika_5.py] [nathan_ai.py]
Traceback (most recent call last):
  File "othello_game.py", line 157, in <module>
    player1 = AiPlayerInterface(sys.argv[1],1)
  File "othello_game.py", line 36, in __init__
    self.process = subprocess.Popen(['python3',filename], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
  File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 800, in __init__
    restore_signals, start_new_session)
  File "C:\ProgramData\Anaconda3\lib\subprocess.py", line 1207, in _execute_child
    startupinfo)
FileNotFoundError: [WinError 2] The system cannot find the file specified

init 编码为:

def __init__(self, filename, color):
    self.color = color
    self.process = subprocess.Popen(['python3',filename], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    name = self.process.stdout.readline().decode("ASCII").strip()
    print("AI introduced itself as: {}".format(name))
    self.name = name
    self.process.stdin.write((str(color)+"\n").encode("ASCII"))
    self.process.stdin.flush()

导入语句是:

import sys
import subprocess
from threading import Timer
from othello_shared import find_lines, get_possible_moves, play_move, get_score

任何帮助将不胜感激,只是学习子流程。[1]:https ://www.instructables.com/id/Othello-Artificial-Intelligence/

标签: python-3.xwindowssubprocess

解决方案


感谢:How to use subprocess.Popen with built-in command on Windows (Dinesh Pundkar) 编辑只是一行:self.process = subprocess.Popen(['python',filename], shell=True, stdin=subprocess .PIPE,标准输出=子进程.PIPE)


推荐阅读