Re: PermissionError: [Errno 13] Permission denied: 'Abc.xlsx'
"Jonathan Hartley" <[email protected]> Wed, 09 Feb 2022 06:55:14 -0600
| Newsgroups | gmane.comp.python.org.uk |
|---|---|
| Message-ID | <[email protected]> |
--===============0795886567596988979==
Content-Type: multipart/alternative;
boundary=e06c8232d6bf4222833d9140cd0e01df
--e06c8232d6bf4222833d9140cd0e01df
Content-Type: text/plain
You might consider the idea that a script which modifies the spreadsheet should read from one file, and write to a different one. This might not fit your scenario, but if it does, then the write will never encounter the locking exception.
On Wed, Feb 9, 2022, at 03:58, SW wrote:
> Responding to list in case this helps someone else as well:
>
> When you open a file in Window ("when the excel is already open following error") there will generally (or maybe always, I don't recall precisely) be an exclusive lock taken on the file.
> This means that while another application has a file open you'll get this sort of error when you try to access the file in any way.
>
> Therefore, the solution is to make sure not to have the file open in another application while trying to run your script on it.
>
> For more information you'll want to search for things like "Windows file locking".
>
> Thanks,
> S
> On 09/02/2022 09:42, Arshad Noman wrote:
>> When I enter data using Tkinter form in an Excel file when the excel file is closed there is no error but when I enter data using Tkinter form when the excel is already open following error comes:
>>
>>
>>
>> Exception in Tkinter callback
>> Traceback (most recent call last):
>> File "C:\Users\Dani Brothers\Anaconda3\lib\tkinter\__init__.py", line 1705, in __call__
>> return self.func(*args)
>> File "D:/Python/Book Bank/New folder/PyCharm/Final/Excel.py", line 61, in SaveBook
>> workbook.save(filename="BookBank.xlsx")
>> File "C:\Users\Dani Brothers\Anaconda3\lib\site-packages\openpyxl\workbook\workbook.py", line 392, in save
>> save_workbook(self, filename)
>> File "C:\Users\Dani Brothers\Anaconda3\lib\site-packages\openpyxl\writer\excel.py", line 291, in save_workbook
>> archive = ZipFile(filename, 'w', ZIP_DEFLATED, allowZip64=True)
>> File "C:\Users\Dani Brothers\Anaconda3\lib\zipfile.py", line 1207, in __init__
>> self.fp = io.open(file, filemode)
>> PermissionError: [Errno 13] Permission denied: 'Abc.xlsx'
>>
>>
>>
>> What to do to correct this error? I have already searched on google search many times but no solution was found.
>>
>> _______________________________________________
>> python-uk mailing list
>> [email protected]
>> https://mail.python.org/mailman/listinfo/python-uk
>>
>
> _______________________________________________
> python-uk mailing list
> [email protected]
> https://mail.python.org/mailman/listinfo/python-uk
>
--
Jonathan Hartley USA, Central(UTC-6)
twitter:@tartley https://tartley.com
--e06c8232d6bf4222833d9140cd0e01df
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE html><html><head><title></title><style type=3D"text/css">p.Mso=
Normal,p.MsoNoSpacing{margin:0}</style></head><body><div>You might consi=
der the idea that a script which modifies the spreadsheet should read fr=
om one file, and write to a different one. This might not fit your scena=
rio, but if it does, then the write will never encounter the locking exc=
eption.</div><div><br></div><div>On Wed, Feb 9, 2022, at 03:58, SW wrote=
:<br></div><blockquote type=3D"cite" id=3D"qt" style=3D""><div class=3D"=
qt-moz-cite-prefix"><div>Responding to list in case this helps
someone else as well:<br></div><div> <br></div><div> When you open=
a file in Window ("<span style=3D"color:rgba(0, 0, 0, 0.87);"><span cla=
ss=3D"font" style=3D"font-family:Roboto, RobotoDraft, Helvetica, Arial, =
sans-serif;"><span class=3D"size" style=3D"font-size:14px;">when
the excel is already open following error") there will generally
(or maybe always, I don't recall precisely) be an exclusive lock
taken on the file.<br> This means that while another application=
has a file open you'll
get this sort of error when you try to access the file in any
way.<br> <br> Therefore, the solution is to make sure not to hav=
e the file
open in another application while trying to run your script on
it.<br> <br> For more information you'll want to search for thin=
gs like
"Windows file locking".<br> <br> Thanks,<br> S<br> </span></span=
></span></div><div> On 09/02/2022 09:42, Arshad Noman wrote:<br></div></=
div><blockquote type=3D"cite" cite=3D"mid:CA+0oV2jvW10yViY6Qhc910rvCF0FF=
[email protected]"><div dir=3D"ltr"><div class=3D"qt-=
gmail_quote"><div dir=3D"ltr"><div class=3D"qt-gmail_quote"><div dir=3D"=
ltr"><div><span style=3D"color:rgba(0, 0, 0, 0.87);"><span class=3D"font=
" style=3D"font-family:Roboto, RobotoDraft, Helvetica, Arial, sans-serif=
;"><span class=3D"size" style=3D"font-size:14px;">When
I enter data using Tkinter form in an Excel file when
the excel file is closed there is no error but when I
enter data using Tkinter form when the excel is
already open following error comes:</span></span></spa=
n><br></div><div> <br></div><div> <br></div><div> <br></div><div> <span =
style=3D"color:rgba(0, 0, 0, 0.87);"><span class=3D"font" style=3D"font-=
family:Roboto, RobotoDraft, Helvetica, Arial, sans-serif;"><span class=3D=
"size" style=3D"font-size:14px;">Exception
in Tkinter callback</span></span></span><br></div><div=
> <span style=3D"color:rgba(0, 0, 0, 0.87);"><span class=3D"font" style=3D=
"font-family:Roboto, RobotoDraft, Helvetica, Arial, sans-serif;"><span c=
lass=3D"size" style=3D"font-size:14px;">Traceback
(most recent call last):</span></span></span><br></div=
><div> <span style=3D"color:rgba(0, 0, 0, 0.87);"><span class=3D"font" s=
tyle=3D"font-family:Roboto, RobotoDraft, Helvetica, Arial, sans-serif;">=
<span class=3D"size" style=3D"font-size:14px;">File
"C:\Users\Dani
Brothers\Anaconda3\lib\tkinter\__init__.py", line
1705, in __call__</span></span></span><br></div><div> =
<span style=3D"color:rgba(0, 0, 0, 0.87);"><span class=3D"font" style=3D=
"font-family:Roboto, RobotoDraft, Helvetica, Arial, sans-serif;"><span c=
lass=3D"size" style=3D"font-size:14px;">return
self.func(*args)</span></span></span><br></div><div> <=
span style=3D"color:rgba(0, 0, 0, 0.87);"><span class=3D"font" style=3D"=
font-family:Roboto, RobotoDraft, Helvetica, Arial, sans-serif;"><span cl=
ass=3D"size" style=3D"font-size:14px;">File
"D:/Python/Book Bank/New
folder/PyCharm/Final/Excel.py", line 61, in SaveBook</=
span></span></span><br></div><div> <span style=3D"color:rgba(0, 0, 0, 0.=
87);"><span class=3D"font" style=3D"font-family:Roboto, RobotoDraft, Hel=
vetica, Arial, sans-serif;"><span class=3D"size" style=3D"font-size:14px=
;">workbook.save(filename=3D"BookBank.xlsx")</span></span></span><br></d=
iv><div> <span style=3D"color:rgba(0, 0, 0, 0.87);"><span class=3D"font"=
style=3D"font-family:Roboto, RobotoDraft, Helvetica, Arial, sans-serif;=
"><span class=3D"size" style=3D"font-size:14px;">File
"C:\Users\Dani
Brothers\Anaconda3\lib\site-packages\openpyxl\workbook=
\workbook.py",
line 392, in save</span></span></span><br></div><div> =
<span style=3D"color:rgba(0, 0, 0, 0.87);"><span class=3D"font" style=3D=
"font-family:Roboto, RobotoDraft, Helvetica, Arial, sans-serif;"><span c=
lass=3D"size" style=3D"font-size:14px;">save_workbook(self,
filename)</span></span></span><br></div><div> <span st=
yle=3D"color:rgba(0, 0, 0, 0.87);"><span class=3D"font" style=3D"font-fa=
mily:Roboto, RobotoDraft, Helvetica, Arial, sans-serif;"><span class=3D"=
size" style=3D"font-size:14px;">File
"C:\Users\Dani
Brothers\Anaconda3\lib\site-packages\openpyxl\writer\e=
xcel.py",
line 291, in save_workbook</span></span></span><br></d=
iv><div> <span style=3D"color:rgba(0, 0, 0, 0.87);"><span class=3D"font"=
style=3D"font-family:Roboto, RobotoDraft, Helvetica, Arial, sans-serif;=
"><span class=3D"size" style=3D"font-size:14px;">archive
=3D ZipFile(filename, 'w', ZIP_DEFLATED,
allowZip64=3DTrue)</span></span></span><br></div><div>=
<span style=3D"color:rgba(0, 0, 0, 0.87);"><span class=3D"font" style=3D=
"font-family:Roboto, RobotoDraft, Helvetica, Arial, sans-serif;"><span c=
lass=3D"size" style=3D"font-size:14px;">File
"C:\Users\Dani Brothers\Anaconda3\lib\zipfile.py",
line 1207, in __init__</span></span></span><br></div><=
div> <span style=3D"color:rgba(0, 0, 0, 0.87);"><span class=3D"font" sty=
le=3D"font-family:Roboto, RobotoDraft, Helvetica, Arial, sans-serif;"><s=
pan class=3D"size" style=3D"font-size:14px;">self.fp
=3D io.open(file, filemode)</span></span></span><br></=
div><div> <span style=3D"color:rgba(0, 0, 0, 0.87);"><span class=3D"font=
" style=3D"font-family:Roboto, RobotoDraft, Helvetica, Arial, sans-serif=
;"><span class=3D"size" style=3D"font-size:14px;">PermissionError:
[Errno 13] Permission denied: 'Abc.xlsx'</span></span>=
</span><br></div><div> <br></div><div> <br></div><div> <br></div><div> <=
span style=3D"color:rgba(0, 0, 0, 0.87);"><span class=3D"font" style=3D"=
font-family:Roboto, RobotoDraft, Helvetica, Arial, sans-serif;"><span cl=
ass=3D"size" style=3D"font-size:14px;">What
to do to correct this error? I have already searched
on google search many times but no solution was found.=
</span></span></span><br></div></div></div></div></div></div><div><br></=
div><pre class=3D"qt-moz-quote-pre">____________________________________=
___________
python-uk mailing list
<a class=3D"qt-moz-txt-link-abbreviated" href=3D"mailto:python-uk@python=
.org">[email protected]</a>
<a class=3D"qt-moz-txt-link-freetext" href=3D"https://mail.python.org/ma=
ilman/listinfo/python-uk">https://mail.python.org/mailman/listinfo/pytho=
n-uk</a>
<br></pre></blockquote><div><br></div><div>_____________________________=
__________________<br></div><div>python-uk mailing list<br></div><div><a=
href=3D"mailto:[email protected]">[email protected]</a><br></div>=
<div><a href=3D"https://mail.python.org/mailman/listinfo/python-uk">http=
s://mail.python.org/mailman/listinfo/python-uk</a><br></div><div><br></d=
iv></blockquote><div><br></div><div id=3D"sig88274680"><div class=3D"sig=
nature"><span class=3D"font" style=3D"font-family:menlo, consolas, monos=
pace, sans-serif;"><span class=3D"colour" style=3D"color:rgb(128, 128, 1=
28);">--</span></span><br></div><div class=3D"signature"><span class=3D"=
font" style=3D"font-family:menlo, consolas, monospace, sans-serif;"><spa=
n class=3D"colour" style=3D"color:rgb(128, 128, 128);">Jonathan Hartley&=
nbsp; USA, Central(UTC-6)</span></span><br></div><div class=3D"signature=
"><span class=3D"font" style=3D"font-family:menlo, consolas, monospace, =
sans-serif;"><span class=3D"colour" style=3D"color:rgb(128, 128, 128);">=
<span class=3D"font" style=3D"font-family:menlo, consolas, monospace, sa=
ns-serif;"><span class=3D"colour" style=3D"color:rgb(128, 128, 128);"><s=
pan class=3D"font" style=3D"font-family:menlo, consolas, monospace, sans=
-serif;"><span class=3D"colour" style=3D"color:rgb(128, 128, 128);">twit=
ter:@tartley </span></span><a href=3D"http://tartley.com"><span cl=
ass=3D"font" style=3D"font-family:menlo, consolas, monospace, sans-serif=
;"><span class=3D"colour" style=3D"color:rgb(128, 128, 128);">https://ta=
rtley.com</span></span></a></span></span></span></span><br></div></div><=
/body></html>
--e06c8232d6bf4222833d9140cd0e01df--
--===============0795886567596988979==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
python-uk mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-uk
--===============0795886567596988979==--