PrisonersDilemmaTournament icon indicating copy to clipboard operation
PrisonersDilemmaTournament copied to clipboard

Error when running the code

Open 1randomguy opened this issue 3 years ago • 11 comments

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.

1randomguy avatar May 20 '21 13:05 1randomguy

Also running into this.

Bates550 avatar May 20 '21 14:05 Bates550

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 avatar May 20 '21 14:05 jherndon8

Or try making this edit

jherndon8 avatar May 20 '21 15:05 jherndon8

Same issue, using VScode

hand-burger avatar May 20 '21 16:05 hand-burger

enter the code folder before starting the script

zelosos avatar May 20 '21 17:05 zelosos

enter the code folder before starting the script

Didn't work

hand-burger avatar May 20 '21 17:05 hand-burger

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

ThatXliner avatar May 20 '21 18:05 ThatXliner

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

hand-burger avatar May 20 '21 18:05 hand-burger

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

carykh avatar May 21 '21 12:05 carykh

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)

ThatXliner avatar May 21 '21 15:05 ThatXliner

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

Barigamb738 avatar May 22 '21 11:05 Barigamb738