簡體   English   中英

在 CentOS6 中運行 python 子進程和 Libreoffice 6.2 時無法打開顯示錯誤

[英]Failed to Open Display error while running python subprocess and Libreoffice 6.2 in CentOS6

我需要運行Libreoffice --covert-to to 將 excel 文件轉換為 html 頁面。 當前代碼在 Windows 機器中運行良好。 但是在 AWS、CentOS6 中,它會產生錯誤“無法打開顯示” 這是我的代碼

import subprocess
cwdir = '/opt/libreoffice6.2/program'
excel_path = '/home/ec2-user/PythonCode/testing/Book1.xlsx'
dest_path = '/home/ec2-user/PythonCode/testing'
html_command = ["soffice", "--headless", "--convert-to", "html", "--outdir", 
               dest_path, excel_path]
subprocess.run(html_command, shell=True, cwd=cwdir)`

我能夠通過一些小的更改將 excel 文件轉換為 html 文件。 列表中的值不起作用,因此我必須將soffice convert-to查詢作為字符串值提供,該文件夾包含輸入 excel 文件和目標文件夾,其中要存儲的 html 文件必須不同。

import subprocess
cwdir = '/opt/libreoffice6.2/program'
excel_path = '/home/ec2-user/PythonCode/testing/Book1.xlsx'
dest_path = '/home/ec2-user/PythonCode/testing/output'
html_command = r"soffice --headless --convert-to html --outdir " + " " + dest_path + " " + excel_path
subprocess.run(html_command, shell=True, cwd=cwdir)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM