0

A team of us have worked on this for hours to no avail. If you clone https://github.com/sds-dubois/snake.ai onto a Mac and run it with Python 2.7 it works like a charm. When I try to do the same on Windows 10 with an Anaconda Python 2.7 environment, after installing pygame, numpy and sklearn, I get the following when I run $ python controller.py:

pygame 1.9.6
Hello from the pygame community. https://www.pygame.org/contribute.html
Traceback (most recent call last):
  File "controller.py", line 121, in <module>
    rl_hp = load_from(config.filename + ".p")
  File "C:\Users\mcram\Documents\Github\CS221-AI\MultiplayerSnake\snake-ai-slither\snake.ai\hp.py", line 46, in load_from
    out = pickle.load(fin)
  File "C:\Users\mcram\Anaconda3\envs\snake27\lib\pickle.py", line 1384, in load
    return Unpickler(file).load()
  File "C:\Users\mcram\Anaconda3\envs\snake27\lib\pickle.py", line 864, in load
    dispatch[key](self)
  File "C:\Users\mcram\Anaconda3\envs\snake27\lib\pickle.py", line 1075, in load_inst
    klass = self.find_class(module, name)
  File "C:\Users\mcram\Anaconda3\envs\snake27\lib\pickle.py", line 1130, in find_class
    __import__(module)
ImportError: No module named hp

There is a file called hp.py and we can see that it is run (the 2nd call in the Traceback is File "C:\Users\mcram\Documents\Github\CS221-AI\MultiplayerSnake\snake-ai-slither\snake.ai\hp.py", line 46, in load_from which is from hp.py), so we're not understanding why I'm getting ImportError: No module named hp.

I tried multiple different Anaconda environments to no avail. Running from Spyder and PyCharm give the exact same result. Copying the entirely of hp.py into controller.py doesn't help. I also tried to 'hard code' the file path, with the different variations of slashes (e.g. forward, backward, double back, double forward), but that didn't work either. Any suggestions would be appreciated.

Mark Cramer
  • 2,614
  • 5
  • 33
  • 57
  • 1
    As you can see with the last line of the traceback, it's actually the `pickle.py` file that's trying to find `hp.py`. Your own project files manage to import it, but this one throws the `ImportError`. You might want to check out [pickle: yet another ImportError: No module named my_module](https://stackoverflow.com/questions/33968685/pickle-yet-another-importerror-no-module-named-my-module) since it links other such issues, plus uses Anaconda too. – shriakhilc Jun 02 '19 at 05:27
  • 1
    I love SO so much! Yes, I saw that post, but it's long and complicated. I read it again, however, and the punchline is at the bottom. In `hp.py` I changed `with open("data/" + filename, "rb") as fin:` to `with open("data/" + filename, "r") as fin:` and it works! I removed a single character. It's very annoying, however, that this would be a problem. Thank you for your assistance. I'll give you the checkmark is you'd like to write and answer. – Mark Cramer Jun 02 '19 at 06:07
  • Glad I could help! – shriakhilc Jun 02 '19 at 06:16

0 Answers0