snoopyjc / xls2xlsx

Convert xls file to xlsx (in python 3)
MIT License
54 stars 19 forks source link

File xls2xlsx/fontnames.yaml does not exist #17

Open Jancs-E opened 1 year ago

Jancs-E commented 1 year ago

trying to convert xls to xlsx I get error:

File "script.py", line XXX, in x2x.to_xlsx("output.xlsx")
File "/usr/lib64/python3.9/site-packages/xls2xlsx/xls2xlsx.py", line 190, in to_xlsx return self.h2x.to_xlsx(filename=filename) File "/usr/lib64/python3.9/site-packages/xls2xlsx/htmlxls2xlsx.py", line 1017, in to_xlsx font_utils = FontUtils() File "/usr/lib64/python3.9/site-packages/xls2xlsx/htmlxls2xlsx.py", line 102, in init with open(fontnames_file, 'w') as fn: PermissionError: [Errno 13] Permission denied: '/usr/lib64/python3.9/site-packages/xls2xlsx/fontnames.yaml'

Its correct as such file doe not exist in the directory /usr/lib64/python3.9/site-packages/xls2xlsx/ Installation of the module went w/o errors

snoopyjc commented 1 year ago

I’ll take a look. From the traceback, it’s trying to create the font mapping file and you don’t have permission to write to that dir. Try “run as administrator” or sudo. Once it’s created it shouldn’t have to create it again.

Jancs-E commented 1 year ago

I would say that it is most incorrect solution of the problem - the fact that module is installed system-wide does not mean that the modules using it should be run with elevated user rights. May be the missing file should be generated at the install time?

snoopyjc commented 1 year ago

Like I said - I’ll take a look. Maybe I can create the file during installation. I was giving you an avoidance procedure for now.

yan-hic commented 1 year ago

I am facing the exact same error in a different environment, namely a cloud function - on GCP, but should apply on any platform/provider preventing root access: OSError: [Errno 30] Read-only file system: '/layers/google.python.pip/pip/lib/python3.11/site-packages/xls2xlsx/fontnames.yaml'

@snoopyjc I can have a look as it may just be a matter of redirecting to a temp dir or file.

snoopyjc commented 1 year ago

I think what needs to be done is this file needs to be created during the installation process, not when the program is first run

yan-hic commented 1 year ago

Actually it's at runtime that

The culprit is https://github.com/snoopyjc/xls2xlsx/blob/642f980cd543cab0217e0d63e0e2568987c4ea90/xls2xlsx/htmlxls2xlsx.py#L52 as one can usually not save/edit in the site packages... unless run locally as admin as you suggested.

I suggest using tempfile.gettempdir() to store the file as it is stable i.e. read or written from same place between calls. As per the specs, using the working dir is only as last resort.