如何修复:AttributeError:模块“neat”没有属性“config”

2024-05-07

我正在浏览使用发现的 NEAT 神经网络 API 玩 flappybird 的 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):
    """
    runs the NEAT algorithm to train a neural network to play flappy bird.
    :param config_file: location of config file
    :return: None
    """
    config = neat.config.Config(neat.DefaultGenome, neat.DefaultReproduction,
                         neat.DefaultSpeciesSet, neat.DefaultStagnation,
                         config_file)

    # Create the population, which is the top-level object for a NEAT run.
    p = neat.Population(config)

    # Add a stdout reporter to show progress in the terminal.
    p.add_reporter(neat.StdOutReporter(True))
    stats = neat.StatisticsReporter()
    p.add_reporter(stats)
    #p.add_reporter(neat.Checkpointer(5))

    # Run for up to 50 generations.
    winner = p.run(eval_genomes, 50)

    # show final stats
    print('\nBest genome:\n{!s}'.format(winner))


if __name__ == '__main__':
    # Determine path to configuration file. This path manipulation is
    # here so that the script will run successfully regardless of the
    # current working directory.
    local_dir = os.path.dirname(__file__)
    config_path = os.path.join(local_dir, 'config-feedforward.txt')
    run(config_path)

但是我查看了 Neat 文档发现here https://neat-python.readthedocs.io/en/latest/module_summaries.html#config.Config它说这个属性确实存在。如果相关的话,我正在 Mac 上使用 Pycharm。有谁知道错误来自哪里?


我遇到过同样的问题。 当我安装整齐的Python而不是仅仅通过pip整齐地运行相同的代码后,我的问题得到了解决。 所以尝试这样做

pip 安装整洁的 python

另请确保您的电脑中已存在requirements.txt 中给出的所有软件包。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何修复:AttributeError:模块“neat”没有属性“config” 的相关文章