I'm attempting to create a .txt file as the output from a larger python script I'm running within ArcMap. The code I'm having trouble goes like this: x = open('adfd.txt', 'w'), and my error message says:

Runtime error
Traceback (most recent call last):
File "<string>", line 1, in <module>
IOError: [Errno 13] Permission denied: 'adfd.txt'

I've tried this on ArcMap installations on other computers, as well as on non-Esri python interpreters on my own computer (Anaconda's Spyder), and it works fine there, so I'm pretty sure it's something going on with how my installation of ArcMap handles permissions. Does anyone know what might be going on here? I'd like to avoid reinstalling if possible, because that's a big pain with my student license.

Edit prompted by @AlexGIS: When I try to specify a different existing folder, I can change folders fine using arcpy.env.workspave, but I still get the same error message from the open command. When I try to make a new directory within ArcMap using os.mkdir I get a new error message: os.mkdir('asdfadfa') Runtime error Traceback (most recent call last): File "<string>", line 1, in <module> WindowsError: [Error 5] Access is denied: 'asdfadfa'

Maybe a new clue?

  • is that all your code? Does adfd.txt exist? – Midavalo Apr 13 '16 at 18:22
  • There's a lot more, but that's all that's relevant to this problem (I can get every other line to run without any error messages). The file doesn't exist, but it should just create one, or wipe the old one if it does exist. docs.python.org/2/tutorial/… – LGelb Apr 13 '16 at 18:24
  • 1
    If you go to the folder containing the file can you manually create a file? Or delete a file? Open the file? – MaryBeth Apr 13 '16 at 18:28
  • 1
    Can you try specifying a different folder in which to create the file? For example, create a new folder like c:\pytest and then change your code to be x = open('c:\\pytest\\adfd.txt', 'w') and see what happens. – alexGIS Apr 13 '16 at 18:31
  • @MaryBeth Yes, I can create, edit, and delete files from that directory manually from windows explorer. – LGelb Apr 13 '16 at 18:32

You need to change the working directory for os and workspace.

So, if your project directory was 'c:\testing', then you'd want to do something like this:

mydir = r'c:\testing'
arcpy.env.workspace = mydir

Now when you make new files, that's the folder your new file will go.

  • Yes, that fixes it! Thank you so much for troubleshooting this for me! I wish I had the reputation to be able to give you an upvote. – LGelb Apr 13 '16 at 19:51
  • Glad to help. @Jim's answers gave me some ideas to test out. I learned something too! – alexGIS Apr 13 '16 at 20:10

Not the answer you're looking for? Browse other questions tagged or ask your own question.