PermissionError [errno 13] when running openpyxl python script in Komodo
Asked Answered
B

5

10

I am having trouble using openpyxl scripts in Komodo edit 9 and python 3.4 on Windows 7. I copied some openpyxl code to learn, but it won't execute from Komodo. I receive a permission error 13. I checked my path and python34 is present. The same script will run when I use IDLE or Command Prompt. My Komodo command is currently: %(python3) -u %F Any ideas on what may be causing this issue? The code and error are included below

from openpyxl import Workbook
from openpyxl.compat import range
from openpyxl.cell import get_column_letter

wb = Workbook()

dest_filename = 'empty_book.xlsx'

ws1 = wb.active
ws1.title = "range names"

for row in range(1, 40):
    ws1.append(range(600))

ws2 = wb.create_sheet(title="Pi")

ws2['F5'] = 3.14

ws3 = wb.create_sheet(title="Data")
for row in range(10, 20):
    for col in range(27, 54):
        _ = ws3.cell(column=col, row=row, value="%s" % get_column_letter(col))
print(ws3['AA10'].value)
wb.save(filename = dest_filename)

-------Begin Error-----------

AA
Traceback (most recent call last):
  File "C:\Users\PF15043\Desktop\Scripts\Ggizmo\excelReader.py", line 26, in <module>
    wb.save(filename = dest_filename)
  File "C:\Python34\lib\site-packages\openpyxl-2.3.0b1-py3.4.egg\openpyxl\workbook\workbook.py", line 254, in save
    save_workbook(self, filename)
  File "C:\Python34\lib\site-packages\openpyxl-2.3.0b1-py3.4.egg\openpyxl\writer\excel.py", line 195, in save_workbook
    writer.save(filename, as_template=as_template)
  File "C:\Python34\lib\site-packages\openpyxl-2.3.0b1-py3.4.egg\openpyxl\writer\excel.py", line 177, in save
    archive = ZipFile(filename, 'w', ZIP_DEFLATED, allowZip64=True)
  File "C:\Python34\lib\zipfile.py", line 923, in __init__
    self.fp = io.open(file, modeDict[mode])
PermissionError: [Errno 13] Permission denied: 'empty_book.xlsx'
Bulky answered 30/6, 2015 at 20:2 Comment(0)
G
12

This is simply an error from the operating system telling you that you don't have permissions to create a file where you're trying to. You should specify the full path of the file you're trying to create.

Georgy answered 1/7, 2015 at 6:39 Comment(3)
Brilliant! Thank you. I had tried using the full path before, but I had forgotten to escape the backslashes. Thank you so much for your help.Bulky
Tip: use os.path.join() for paths so you don't have to worry about the path separator and escaping it.Georgy
That's a good tip. This gives me the perfect chance to start learning the os.path module. Thanks again for the help.Bulky
R
25

I faced the same problem yesterday, but because I dumbly let the workbook open while trying to run the script. Closing it fixed the issue.

Rotten answered 12/2, 2016 at 16:31 Comment(0)
G
12

This is simply an error from the operating system telling you that you don't have permissions to create a file where you're trying to. You should specify the full path of the file you're trying to create.

Georgy answered 1/7, 2015 at 6:39 Comment(3)
Brilliant! Thank you. I had tried using the full path before, but I had forgotten to escape the backslashes. Thank you so much for your help.Bulky
Tip: use os.path.join() for paths so you don't have to worry about the path separator and escaping it.Georgy
That's a good tip. This gives me the perfect chance to start learning the os.path module. Thanks again for the help.Bulky
Y
0

By default, your location may be set into C drive which is an OS part.

Just try like this, I also got the same problem`.

  location = "E:\output.xlsx"
  data = []
  writer = pd.ExcelWriter(location)
Yanez answered 10/7, 2019 at 17:54 Comment(0)
M
0

If you open the excel whatever you created, it will show like that. So before you are running the code,close your destination_file folder.

Mulvihill answered 10/1, 2023 at 6:57 Comment(0)
D
0

i was facing the same issue say that:

PermissionError: [Errno 13] Permission denied: 'D:\test'

so i was change from folder to file, and it's work, hope it help some one.

change from this:

book.save("D:\\test")

to this:

book.save("D:\\test\\issue-data.xlsx")
Distraint answered 7/6, 2023 at 3:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.