简体   繁体   English

导入错误:无法从“_ctypes”导入名称“COMError”(/usr/lib/python3.7/lib-dynload/_ctypes.cpython-37m-x86_64-linux-gnu.so)

[英]ImportError: cannot import name 'COMError' from '_ctypes' (/usr/lib/python3.7/lib-dynload/_ctypes.cpython-37m-x86_64-linux-gnu.so)

import os
import glob
import comtypes.client

from PyPDF2 import PdfFileMerger
 
 
def docxs_to_pdf():
    """Converts all word files in pdfs and append them to pdfslist"""
    word = comtypes.client.CreateObject('Word.Application')
    pdfslist = PdfFileMerger()
    x = 0
    for f in glob.glob("*.docx"):
        input_file = os.path.abspath(f)
        output_file = os.path.abspath("demo" + str(x) + ".pdf")
        # loads each word document
        doc = word.Documents.Open(input_file)
        doc.SaveAs(output_file, FileFormat=16+1)
        doc.Close() # Closes the document, not the application
        pdfslist.append(open(output_file, 'rb'))
        x += 1
    word.Quit()
    return pdfslist
 
def joinpdf(pdfs):
    """Unite all pdfs"""
    with open("result.pdf", "wb") as result_pdf:
        pdfs.write(result_pdf)
 
def main():
    """docxs to pdfs: Open Word, create pdfs, close word, unite pdfs"""
    pdfs = docxs_to_pdf()
    joinpdf(pdfs)
 
main()

I am using jupyter notebook and it throw an error what should I do: this is error message我正在使用 jupyter notebook,它抛出错误我该怎么办:这是错误消息

I am going to convert many.doc file to one pdf. Help me I am beginner in this field.我要将 many.doc 文件转换为一个 pdf。帮助我,我是这个领域的初学者。

Make sure you have all the dependencies installed in your environment.确保您的环境中安装了所有依赖项。 You can use pip to install comtypes.client, simply pass this in your terminal:您可以使用 pip 安装 comtypes.client,只需将其传递到您的终端即可:

pip install comtypes

You can download _ctypes from sourceforge: https://sourceforge.net/projects/ctypes/files/ctypes/1.0.2/ctypes-1.0.2.tar.gz/download?use_mirror=deac-fra您可以从 sourceforge 下载 _ctypes: https://sourceforge.net/projects/ctypes/files/ctypes/1.0.2/ctypes-1.0.2.tar.gz/download?use_mirror=deac-fra

Using docx2pdf does seem easier for your task though.不过,使用 docx2pdf 似乎更容易完成您的任务。 After you converted the files you can use PyPDF2 to append them.转换文件后,您可以使用 PyPDF2 将其转换为 append。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法从“cv2.cv2”(/usr/local/lib/python3.7/dist-packages/cv2/cv2.cpython-37m-x86_64-linux-gnu.so)导入名称“_registerMatType” - cannot import name '_registerMatType' from 'cv2.cv2' (/usr/local/lib/python3.7/dist-packages/cv2/cv2.cpython-37m-x86_64-linux-gnu.so) Colab PyTorch | 导入错误:/usr/local/lib/python3.7/dist-packages/_XLAC.cpython-37m-x86_64-linux-gnu.so - Colab PyTorch | ImportError: /usr/local/lib/python3.7/dist-packages/_XLAC.cpython-37m-x86_64-linux-gnu.so ImportError: 无法从 'urllib' (/usr/lib/python3.7/urllib/__init__.py) 导入名称 'quote' - ImportError: cannot import name 'quote' from 'urllib' (/usr/lib/python3.7/urllib/__init__.py) /lib/x86_64-linux-gnu/libm.so.6:找不到版本“GLIBC_2.29”(/usr/local/lib/python3.7/dist-packages/pyexiv2/lib/libexiv2.so 需要)colab粘性物 - /lib/x86_64-linux-gnu/libm.so.6: version `GLIBC_2.29' not found (required by /usr/local/lib/python3.7/dist-packages/pyexiv2/lib/libexiv2.so) colab goo 无法导入模块“lambda_function”:无法从“ctypes”(/var/lang/lib/python3.7/ctypes/__init__.py)导入名称“WinDLL” - Unable to import module 'lambda_function': cannot import name 'WinDLL' from 'ctypes' (/var/lang/lib/python3.7/ctypes/__init__.py Windows Ubuntu Bash shell 上的 Python3.7 导入错误:无法从 'urllib.request' (/usr/lib/python3.7/urllib/request.py) 导入名称 'HTTPSHandler' - Python3.7 on Windows Ubuntu Bash shell ImportError: cannot import name 'HTTPSHandler' from 'urllib.request' (/usr/lib/python3.7/urllib/request.py) ImportError:即使/usr/lib64/python2.7/lib-dynload/_ssl.so可用,也不会发生名为_ssl的模块 - ImportError: No module named _ssl occurring even when /usr/lib64/python2.7/lib-dynload/_ssl.so is available fc18 ImportError:无法从“变压器”(/usr/local/lib/python3.7/dist-packages/transformers/__init__.py)导入名称“BigBirdTokenizer” - ImportError: cannot import name 'BigBirdTokenizer' from 'transformers' (/usr/local/lib/python3.7/dist-packages/transformers/__init__.py) Python:ImportError:/usr/local/lib/python2.7/lib-dynload/_io.so:undefined symbol:PyUnicodeUCS2_Replace - Python: ImportError: /usr/local/lib/python2.7/lib-dynload/_io.so: undefined symbol: PyUnicodeUCS2_Replace _ctypes.cpython-39-x86_64-linux-gnu.so:未定义的符号:PyFloat_Type 在嵌入式 Python 中加载了 dlopen - _ctypes.cpython-39-x86_64-linux-gnu.so: undefined symbol: PyFloat_Type in embedded Python loaded with dlopen
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM