5

So recently I have found about a NEAT algorithm and wanted to give it a try using NEAT-Python(not sure if this is even the correct source :| ). So I created my virtual environment activated it and installed the neat-python using pip in the VE. When I then tried to run one of the examples from their GitHub page it threw an error like this:

ImportError: No module named visualize

So I checked my source files, and actually the neat-python doesn't include the visualize.py script, however it is in their GitHub repository. I then tried to add it myself by downloading just the visualize.oy script dragging it inside my VE and adding it to all the textfiles the NEAT brought with it, like the installed-filex.txt etc. However it still threw the same error.

I'm still fairly new to VE and GitHub so please don't be too hard on me :] thanks in advance.

-Jorge

J.Paravicini
  • 882
  • 12
  • 39
  • 1
    I'm guessing you tried the example files in their XOR directory? Have you tried simply copying the visualize.py into the same directory as the script you are running? – fpes Jan 20 '17 at 00:08
  • Well this worked, however it would be nice to have it in the lib folder, is there no other way? – J.Paravicini Jan 20 '17 at 02:48
  • I'm sorry I'm not sure what you mean by the lib folder? do you mean where your lib/site-packages directory? copy visualize.py into lib/site-packages/neat/ and modify __init__.py to add the line `import neat.visualize as visualize`. Delete the \_\_pycache__ directory. Make sure you have modules installed: Numpy, GraphViz, and Matplotlib. When you've done the above, you should be able to `import neat` and access `neat.visualize`. I don't recommend doing this though. – fpes Jan 20 '17 at 14:59
  • Honestly I thought this was the correct way to do it and even if it worked, I would like to know why you wouldn't recommend it. – J.Paravicini Jan 20 '17 at 15:01
  • Say you wanted to update your neat module. Your visualize.py file is technically not part of the module. So it wouldn't be updated along with your neat module. In addition, the visualize.py file seems to be written in the context of the examples as opposed to being for general use with the module, so contextually, it doesn't belong there. At some point in the future, you might also forget that this wasn't a part of the module, but your code acts as if it was part of the API. So your code will break in some other neat installation. – fpes Jan 20 '17 at 15:06
  • Thanks for you explanation and you're completely right. I won't move the file to the neat folder. If you want to answer the question I will accept it as the correct one. Thanks again :). – J.Paravicini Jan 20 '17 at 15:11

1 Answers1

6

I think you could simply copying the visualize.py into the same directory as the script you are running.

If you wanted it in your lib/site-packages directory so you could import it with the neat module:

copy visualize.py into lib/site-packages/neat/ and modify __init__.py to add the line import neat.visualize as visualize. Delete the __pycache__ directory. Make sure you have modules installed: Numpy, GraphViz, and Matplotlib. When you've done the above, you should be able to import neat and access neat.visualize.

I don't recommend doing this though for several reasons:

  1. Say you wanted to update your neat module. Your visualize.py file is technically not part of the module. So it wouldn't be updated along with your neat module.
  2. the visualize.py file seems to be written in the context of the examples as opposed to being for general use with the module, so contextually, it doesn't belong there.
  3. At some point in the future, you might also forget that this wasn't a part of the module, but your code acts as if it was part of the API. So your code will break in some other neat installation.
fpes
  • 964
  • 11
  • 22