carykh / PrisonersDilemmaTournament

Watch This Place's awesome video about iterated Prisoner's Dilemma for context! https://www.youtube.com/watch?v=BOvAbjfJ0x0
MIT License
205 stars 160 forks source link

Error when running the code #19

Open 1randomguy opened 3 years ago

1randomguy commented 3 years ago

Hey, I'm relativly new to python and I didn't find anything on this when googling. So when I tried running the code I got this errormessage:

Starting tournament, reading files from exampleStrats
Traceback (most recent call last):
  File "C:/Users/bblom/PycharmProjects/PrisonersDilemmaTournament/code/prisonersDilemma.py", line 120, in <module>
    runFullPairingTournament(STRATEGY_FOLDER, RESULTS_FILE)
  File "C:/Users/bblom/PycharmProjects/PrisonersDilemmaTournament/code/prisonersDilemma.py", line 97, in runFullPairingTournament
    roundHistory = runRound(pair)
  File "C:/Users/bblom/PycharmProjects/PrisonersDilemmaTournament/code/prisonersDilemma.py", line 39, in runRound
    moduleA = importlib.import_module(STRATEGY_FOLDER+"."+pair[0])
  File "C:\Python27\lib\importlib\__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named exampleStrats.alwaysCooperate

It doesn't seem to be related to any of my code so I was wondering what caused it and how I would be able to fix it. I'm using Python 3.9 on Windows with PyCharm.

Bates550 commented 3 years ago

Also running into this.

jherndon8 commented 3 years ago

If you're running from pycharm, it's probably because the current working directory needs to be set. Make sure it's set to the /code folder

jherndon8 commented 3 years ago

Or try making this edit

hand-burger commented 3 years ago

Same issue, using VScode

zelosos commented 3 years ago

enter the code folder before starting the script

hand-burger commented 3 years ago

enter the code folder before starting the script

Didn't work

ThatXliner commented 3 years ago

I had to modify the project structure AND the code. I'll post what I have later

hand-burger commented 3 years ago

My situation seems pretty niche but I did find a way to get it working, I'm using MacOS, VScode, python 3.9.5, using the code runner extension

So, I did use the edit which is linked above and code runner seemed to be using python rather than python3, So I have to type python3 -u 'prisonersDilemma.py' to run it

Hope this can help others

carykh commented 3 years ago

oh shoot, I'm not sure why that's happening for you! Yeah, for me, I do have to be in the '/code' folder before running the code to get it to run, but I've never run into the errors you guys are getting. I hope @hand-burger 's solution works for others as well

ThatXliner commented 3 years ago

What I did was that I moved the example strategies folder outside of the folder prisonersDilemma.py was in (I actually renamed prisonersDilemma.py to __main__.py in a folder called "algch" so I can just run python -m algch to run the tournament)

Barigamb738 commented 3 years ago

i fixed this by doing this: inFolder = os.path.dirname(os.path.realpath(__file__)) + '/' + inFolder