Using soffice within python, Command works in terminal but not in Python subprocess

brucey31 picture brucey31 · Jun 12, 2016 · Viewed 7.4k times · Source

I am having the most frustrating problem with libreoffice in Python

when I run the following in terminal I have no problem at all, the pdf file is produced where I want it and life is dandy:

cd /Applications/LibreOffice.app/Contents/MacOS/

./soffice --convert-to pdf --outdir {output_folder} {path_to_docx_file}/{title}.docx

However when I have tried to add this to my python script:

SOFFICE = r'/Applications/LibreOffice.app/Contents/MacOS/soffice'

subprocess.Popen([SOFFICE, "--convert-to", "pdf", "--outdir", "{output_folder} ", "{path_to_docx_file}/{title}.docx"])

I get an error saying :

Error: source file could not be loaded

I have tried opening up all the permissions of all of the binaries and files and this still doesn't work in the python script. What am I doing wrong?

Answer

M_per picture M_per · Jun 8, 2019

For me it was just a problem with "libreoffice-writer" package missing. So if you're on Debian just:

apt-get install libreoffice-writer