I've encountered a very bizarre error when trying to write files with python. As of today, whenever I try and open a file in write mode, python throws the error 'No such file or directory', even if the directory definitely exists. All other python functionality seems to be working, including reading files.
A simple example of the problem, when run using the command line from my documents:
>>> with open('test.csv', 'w') as f:
... pass
...
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
FileNotFoundError: [Errno 2] No such file or directory: 'test.csv'
I'm using a windows 10 machine, python 3.7, with conda environments specific to projects I'm working on.
I have tried:
- Restarting
- Creating a clean conda environment (conda create --name test python=3.7)
- Running in base without a conda environment
- Providing the path as an absolute rather than relative, i.e.
C:/Users/<myname>/Documents/test.csv
- Trying to run this in other directories
The only success I've had is when running the code with append mode. If I try and create a file as above using mode='a' it throws the error, however if I manually create an empty file, I can append into it.
I really have no idea how to resolve this, other than to completely remove anaconda and python and re-install.