I had the same issue, but my root cause was different than anyone's here. Thought I'd share in case someone else ran into the same issue.
In my case, I had accidentally misplaced my parentheses on the 'with' line:
with (open(os.path.join(curpath, unique_name)), 'w') as fw:
Gave the following error (modified to obscure company details and for clarity):
Traceback (most recent call last):
File "./crap.py", line 60, in uniquify
with (open(os.path.join(curpath, unique_name)), 'w') as fw:
IOError: [Errno 2] No such file or directory: '/<mypath>/bin/python/<filename>'
These parentheses put the 'w' with the with() function, not with open() as intended. I'm surprised it gives this IO Error, which implies it's something wrong with the open() call, which made this much harder to track down than if it obviously came from the with() call.
I didn't believe these results but just modified it again to replicate, and yes, I get the same error.
When I switch parentheses to the correct version:
with (open(os.path.join(curpath, unique_name), 'w')) as fw:
it works as intended.