As Bakuriu stated, the problem was occurring because python already has an I/O module and my directory contained a io.py file. The issue was fixed by renaming the io.py and io.pyc files.