我正在按照一个使用NEAT神经网络API玩Flappy Bird的AI指南进行操作,指南在这里可以找到 这里。
当我运行从Github下载的代码时,出现了以下错误:
"Traceback (most recent call last): File "test.py", line 438, in <module> run(config_path) File "test.py", line 412, in run config = neat.config.Config(neat.DefaultGenome, neat.DefaultReproduction,AttributeError: module 'neat' has no attribute 'config'
问题似乎出自以下代码块:
def run(config_file): """ 运行NEAT算法以训练神经网络玩Flappy Bird。 :param config_file: 配置文件的位置 :return: None """ config = neat.config.Config(neat.DefaultGenome, neat.DefaultReproduction, neat.DefaultSpeciesSet, neat.DefaultStagnation, config_file) # 创建种群,这是NEAT运行的顶级对象。 p = neat.Population(config) # 添加一个标准输出报告器以在终端显示进度。 p.add_reporter(neat.StdOutReporter(True)) stats = neat.StatisticsReporter() p.add_reporter(stats) #p.add_reporter(neat.Checkpointer(5)) # 运行最多50代。 winner = p.run(eval_genomes, 50) # 显示最终统计数据 print('\nBest genome:\n{!s}'.format(winner))if __name__ == '__main__': # 确定配置文件的路径。这里的路径操作是为了确保脚本 # 无论当前工作目录是什么都能成功运行。 local_dir = os.path.dirname(__file__) config_path = os.path.join(local_dir, 'config-feedforward.txt') run(config_path)
然而,我查看了NEAT文档,在这里发现这个属性确实存在。我使用的是Mac上的Pycharm,如果这有相关性的话。有人知道这个错误的来源吗?
回答:
我在相同系统上遇到了相同的问题。
这是我解决它的方法:
打开Pycharm的偏好设置,
转到”项目: 项目名称”,
然后打开”项目解释器”,
在其中通过点击减号按钮卸载”neat”
然后点击加号按钮,搜索”neat-python”并安装它。
我认为Pycharm的自动解释器安装方法在这里出了问题,安装了错误的”neat” :-P希望这对你有用!