【问题标题】:How to fix: AttributeError: module 'neat' has no attribute 'config'如何修复:AttributeError:模块“整洁”没有属性“配置”
【发布时间】:2020-02-22 18:15:57
【问题描述】:

我正在浏览使用找到的 NEAT 神经网络 API here 的 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,它说这个属性确实存在。如果相关的话,我在 Mac 上使用 Pycharm。有谁知道错误来自哪里?

【问题讨论】:

  • 如果你运行import neat; print(neat.__file__)会发生什么?
  • 这个文件中的导入到底是什么(def run(...) 之前)?有import neat,还是import neat.config
  • @mkrieger1 至于我在终端中运行的第一个问题,它给了我“//anaconda3/lib/python3.7/site-packages/neat/__init__.py”
  • @mkrieger1 对于第二个问题,我只导入了整洁,而不是导入整洁.config,但我尝试了整洁.config 和整洁.Config,但似乎都不起作用
  • 当你尝试使用import neat.config时发生了什么?

标签: python neural-network artificial-intelligence config attributeerror


【解决方案1】:

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

pip install -r ./requirements.txt

这解决了我的错误。

【讨论】:

  • 感谢您的建议,但我试过了,它只是说:“错误:无法打开需求文件:[Errno 2] 没有这样的文件或目录:'./requirements.txt'” /跨度>
【解决方案2】:

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

pip 安装整洁的python

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

【讨论】:

    【解决方案3】:

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

    我是这样解决的:

    打开 PyCharms 首选项,

    转到“项目:NAME_OF_PROJECT”,

    然后打开“项目解释器”,

    在那里通过点击减号按钮卸载“整洁”

    然后点击加号按钮并搜索“neat-python”并安装它。

    我认为 PyCharms 自动解释器安装方法在这里出错并安装了错误的“整洁”:-P 希望这对你有用!

    【讨论】:

      【解决方案4】:

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

      【讨论】:

      • 只是为了让您知道,您的答案与一年多前其他人留下的答案非常相似……
      • 请在您的回答中提供更多详细信息。正如目前所写的那样,很难理解您的解决方案。
      猜你喜欢
      • 1970-01-01
      • 2019-05-25
      • 2019-08-25
      • 2020-09-03
      • 2020-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多