How to fix: AttributeError: module 'neat' has no attribute 'config'

How to fix: AttributeError: module 'neat' has no attribute 'config'

我正在 运行 阅读使用 NEAT 神经网络 API 玩 flappy bird 的 AI 指南 here

当我 运行 从 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 它说这个属性确实存在。如果相关的话,我在 mac 上使用 Pycharm。有谁知道错误来自哪里?

我在使用 "import neat"、"import graphviz" 和其他依赖项手动安装库后遇到了同样的问题,但在我使用需求文件后,代码 运行 没问题。在控制台中,打开项目的文件夹并键入:

pip 安装-r ./requirements.txt

这解决了我的错误。

我遇到了同样的问题。 当我 运行 在安装 neat-python 而不是仅仅通过 pip neat 后使用相同的代码时,我的问题得到了解决。 所以尝试这样做

pip install neat-python

还要确保 requirements.txt 中给出的所有软件包都已经存在于您的电脑中。

我在同一个系统上遇到了同样的问题。

我是这样解决的:

打开 PyCharms 首选项,

转到"Project: NAME_OF_PROJECT",

然后打开"Project Interpreter",

点击减号按钮卸载"neat"

然后单击加号按钮并搜索 "neat-python" 并安装它。

我认为 PyCharms 自动解释器安装方法在这里出错并安装错误 "neat" :-P 希望这对你有用!

这对我有效:卸载两个库 'neat' 和 'neat-python',然后重新安装 'neat-python' pip install neat-python,当前版本 0.92