2

This code:

workbook.save(outputf)    
system('open ' + outputf)

generates this error when run on my mac:

sh: /Users/tylerjw/Desktop/jim_data/August2013_report.xlsx: Permission denied

The file was created with openpyxl. I have not been able to reproduce the error outside of my application is a tkinter application that is writing a considerable amount of data to that file.

When I run similar code in windows it doesn't error, it opens excel with the file. The only difference is the absence of the open command.

What could case this error?

tylerjw
  • 802
  • 4
  • 14
  • 28

1 Answers1

3

On my system (mac 10.6.8, python2.7.5, gcc 4.2.1) the following code works fine:

from openpyxl import Workbook
from os import system
wb = Workbook()
outputf = 'test.xlsx'
wb.save(outputf) 
# see below *
system('open ' + outputf)

(see comments: I lost the bet. The error was somewhere else in the code and has nothing to do with system('open ' + whatever))

I bet there is something wrong with permissions in your new file on your system. Maybe you add (docu)

st = os.stat(outputf)
os.chmod(outputf, st.st_mode | stat.stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)

(with input from other link)

in the code instead of my commentary ('# see below *') Then it should be possible to open it by everyone and everything...

If it works, this is a workaround. There is a difference between our system and I do not know what difference. If not, well, I did not test it on my system (because I did not have a problem with the code), write a comment and I might play with the settings or maybe someone else has an idea.

Btw.: In a terminal in your folder: What output gives 'ls -l excelfilename' after execution of the python code? What programming environment do you use? I start the program via 'python2.7 pythonscript.py' in the terminal.

Community
  • 1
  • 1
Stefan Bollmann
  • 640
  • 4
  • 12
  • 32
  • `-rw-r--r-- 1 tylerjw staff 7168 Aug 25 09:25 August2013_report.xlsx` I'm using python 2.7.5 installed with home-brew. To open the application i'm using the command `python2 pythonscript.pyw`. `python2` is a link to my 2.7.5 install. – tylerjw Aug 25 '13 at 04:58
  • output from os.stat: `posix.stat_result(st_mode=33188, st_ino=4647129, st_dev=16777218L, st_nlink=1, st_uid=501, st_gid=20, st_size=7167, st_atime=1377406987, st_mtime=1377412013, st_ctime=1377412013)` – tylerjw Aug 25 '13 at 07:01
  • Ok, the os.stat gives the same output as ls -l. The permissions seem to be ok. At least, it is the same here. Is it possible for you to open a file generated by Excel and saved with Excel with 'open file' in the terminal? – Stefan Bollmann Aug 25 '13 at 12:37
  • I'm sorry but I don't understand your question. Are you asking if it is possible for me to open any Excel file using the terminal? I tested this and it seems to work. Also outside of the application after the file is created I am able to open the file with `open file`. – tylerjw Aug 25 '13 at 14:41
  • If you want to see the problem yourself you can clone my project at [my github repository](https://github.com/tylerjw/jim_tracker). Run the application, set the data directory to the same folder (there are excel files in there you need) then go to reports tab and try to save a report. You should see the error on your console window. The main application is `jim_tracker.pyw`. The offending lines of code are in `reports.py` starting at line 82. – tylerjw Aug 25 '13 at 17:39
  • Ok, this has nothing to do with the 'open ...' thing. The problem is in the code. I try to upload on github. – Stefan Bollmann Aug 26 '13 at 23:08
  • Ok, I forked jim_tracker.pyw and changed reports.py. Now its fine. The error was that in an if else clause some wrong argument was invoked for system(..). – Stefan Bollmann Aug 26 '13 at 23:31