PrisonersDilemmaTournament
PrisonersDilemmaTournament copied to clipboard
Error when running the code
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.
Also running into this.
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
Or try making this edit
Same issue, using VScode
enter the code folder before starting the script
enter the code folder before starting the script
Didn't work
I had to modify the project structure AND the code. I'll post what I have later
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
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
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)
i fixed this by doing this: inFolder = os.path.dirname(os.path.realpath(__file__)) + '/' + inFolder