3

I am running through the guide for an AI that plays flappy bird using the NEAT neural network API found here.

When I run his code downloaded from Github, it gives me the error:

 "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'

The problem seems to be coming from this block of code:

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)

However I looked in the Neat documentation found here and it says that this attribute does in fact exist. I'm using Pycharm on a mac if that is relevant. Does anyone know where the error coming from?

6
  • 1
    What happens if you run import neat; print(neat.__file__)?
    – mkrieger1
    Oct 26, 2019 at 21:07
  • What exactly are the imports in this file (before def run(...))? Is there import neat, or also import neat.config?
    – mkrieger1
    Oct 26, 2019 at 21:09
  • @mkrieger1 As for the first question when I run that in my terminal it gives me "//anaconda3/lib/python3.7/site-packages/neat/__init__.py" Oct 27, 2019 at 18:24
  • @mkrieger1 for the second question I just have import neat, not import neat.config but I tried neat.config and neat.Config and neither seemed to work Oct 27, 2019 at 18:25
  • What happened when you tried to use import neat.config?
    – mkrieger1
    Oct 27, 2019 at 18:57

4 Answers 4

9

I had the same issue. Mine got solved when I ran the same code after installing neat-python instead of just neat through pip. So try doing this

pip install neat-python

Also make sure that all the packages given in requirements.txt is already there in your pc.

4

I've got the same problem on the same system.

Here is how I solved it:

open PyCharms Preferences,

goto "Project: NAME_OF_PROJECT",

then open "Project Interpreter",

in there uninstall "neat" by clicking the minus button

then click the plus button and search for "neat-python" and install that.

I think PyCharms automatic Interpreter installation method gets something wrong here and installs the wrong "neat" :-P Hope this works for you!

0

I had the same problem after I manually installed the libraries using "import neat", "import graphviz" and other dependencies, but after I used the requirements file the code ran fine. In console , open the folder of the project and type:

pip install -r ./requirements.txt

This solved my error.

1
  • Thanks for the suggestion, but I tried that and it just says: "ERROR: Could not open requirements file: [Errno 2] No such file or directory: './requirements.txt' " Oct 28, 2019 at 21:28
0

This works on me: Uninstall both libraries 'neat' and 'neat-python' and then reinstall 'neat-python' pip install neat-python, current version 0.92

2
  • Just to let you know that your answer si very similar to the answers that others have left more than a year ago…
    – EvensF
    Sep 7, 2021 at 3:20
  • Please provide additional details in your answer. As it's currently written, it's hard to understand your solution.
    – Community Bot
    Sep 7, 2021 at 3:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.