環境 CentOS7.2 | Python3.8.1 | LibreOffice6.4.7
一、python安裝
#安裝依賴
yum -y install gcc patch libffi-devel python-devel zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel yum -y install zlib* yum -y install python-setuptools
#安裝python
wget https://www.python.org/ftp/python/3.8.1/Python-3.8.1.tgz tar -zxvf Python-3.8.1.tgz cd Python-3.8.1.tgz ./configure --prefix=/usr/local/python3 make && make install
#建立軟連
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3 ln -s /usr/local/python3/bin/python3 /usr/bin/python3
#升級pip3
pip3 install --upgrade pip
#缺少ssl的情況
yum install openssl yum install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel
#如有低版本的python3,執行如下命令
rpm -qa|grep python3|xargs rpm -ev --allmatches --nodeps //卸載pyhton3
whereis python3 |xargs rm -frv //刪除所有殘余文件
#成功卸載!
whereis python //查看現有安裝的python
二、LibreOffice安裝
#卸載已有的libreoffice
yum erase libreoffice\*
#下載所需要的的安裝包
#解壓
tar -zxvf LibreOffice_6.4.7_Linux_x86-64_rpm_langpack_zh-CN.tar.gz tar -zxvf LibreOffice_6.4.7_Linux_x86-64_rpm_sdk.tar.gz tar -zxvf LibreOffice_6.4.7_Linux_x86-64_rpm.tar.gz
#安裝rpm
#分別到對應解壓目錄里面的RPMS目錄下,執行如下語句(有3個目錄)
yum -y install *.rpm
#查看libreoffice安裝情況
which libreoffice6.4 # 看到路徑:/usr/bin/libreoffice6.4 ll /usr/bin/libreoffice6.4 # 得到路徑:/opt/libreoffice6.4/program/soffice,說明安裝成功:/opt/libreoffice6.4 #增加軟連接 ln -s /opt/libreoffice6.4/program/soffice /usr/bin/soffice
#啟動
/opt/libreoffice6.4/program/soffice --headless --accept="socket,host=127.0.0.1,port=8100;urp;" --nofirststartwizard &
EXMAPLE:
import os import_file_name = "/test/seo.docx" output_file_path = "/test/" os.system("libreoffice6.4 --headless --convert-to pdf %s --outdir %s" % (import_file_name, output_file_path))
