Windows - - IOError: [Errno 13] Permission denied #494

Dooque opened this Issue Jan 18, 2014 · 6 comments


None yet
4 participants

Dooque commented Jan 18, 2014


When I try to save an opened Image object to a file that was previously created by and saved, I have a permission denied error.

Steps to reproduce:
Windows 7 (64-bits)
Python 2.7.3
Pillow 2.3.0

Execute the following code

from PIL import Image
img1 ='I;16', (10, 10))'test.tiff', 'TIFF')
img2 ='test.tiff')'test.tiff')

you should see this error

   1458         if isPath(fp):
-> 1459             fp =, "wb")
   1560             close = 1
   1461         else:

IOError: [Errno 13] Permission denied: 'test.tiff'

Expected behavior:
It should save the image file, no matter how many references to that file I have.

Of course, I have permission to read/write the file inside the directory I am.
I executed it as Admin, I tried to change the mode from the line 1459 to "r+b", and the error is the same.

NOTE: On Ubuntu 12.04 LTS (same python and pillow versions) this code works well.


Dooque commented Jan 19, 2014


I was trying to figure out the problem and I found a possible solution, at least it works for me:

Index: tags/2.3.0/PIL/
--- tags/2.3.0/PIL/ (revision 1344)
+++ tags/2.3.0/PIL/ (working copy)
@@ -1990,7 +1990,7 @@

     if isPath(fp):
         filename = fp
-        fp =, "rb")
+        fp =, "r+b")
         filename = ""



aclark4life commented Mar 17, 2014

I'm not sure I understand the syntax change… @wiredfool ?

@aclark4life aclark4life added the bug label Mar 17, 2014

@aclark4life aclark4life added this to the Future milestone Mar 17, 2014


wiredfool commented Mar 17, 2014

rb is open readonly + binary, r+b is read/write (aka update), binary.

I'm very -1 on setting to use overwrite mode. I think what's happening in the initial case is that image.tiff is still open, preventing the save. This almost sounds like #526, now that I look more closely.


aclark4life commented Mar 17, 2014

Possible duplicate of #526

Dooque commented Mar 17, 2014

Yes, that's the problem, thanks.

when i use it , i only use the pathname, it needs a filename

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment