用python写的PDF转word小代码,开始正常运行,过几天再运行报错。
from pdf2docx import Converter
import os.path
fileFile=input('请输入您想要转换的PDF文件名:')
pdf_file=os.path.abspath(str(fileFile)+".pdf") #获取PDF路径和文件名
name=str(pdf_file)
name=name[0:-4] #切片去后缀
name_1=(str(name)+".docx") #加后缀生成word文件路径和文件名
docx_file=(name_1)
cv=Converter(pdf_file)
cv.convert(docx_file,start=0,end=None)
cv.close()
Traceback (most recent call last):
File "D:\4个人学习\pyshonchengxu\PDF转文字\输入PDF文件名转word.py", line 1, in
from pdf2docx import Converter
File "C:\Users\刘旱雨\AppData\Local\Programs\Python\Python39-32\lib\site-packages\pdf2docx_init.py", line 1, in
from .converter import Converter
File "C:\Users\刘旱雨\AppData\Local\Programs\Python\Python39-32\lib\site-packages\pdf2docx\converter.py", line 7, in
import fitz
File "C:\Users\刘旱雨\AppData\Local\Programs\Python\Python39-32\lib\site-packages\fitz_init.py", line 1, in
from frontend import *
File "C:\Users\刘旱雨\AppData\Local\Programs\Python\Python39-32\lib\site-packages\frontend_init.py", line 1, in
from .events import *
File "C:\Users\刘旱雨\AppData\Local\Programs\Python\Python39-32\lib\site-packages\frontend\events_init.py", line 1, in
from .clipboard import *
File "C:\Users\刘旱雨\AppData\Local\Programs\Python\Python39-32\lib\site-packages\frontend\events\clipboard.py", line 2, in
from ..dom import Event
File "C:\Users\刘旱雨\AppData\Local\Programs\Python\Python39-32\lib\site-packages\frontend\dom.py", line 439, in
from . import dispatcher
File "C:\Users\刘旱雨\AppData\Local\Programs\Python\Python39-32\lib\site-packages\frontend\dispatcher.py", line 15, in
from . import config, server
File "C:\Users\刘旱雨\AppData\Local\Programs\Python\Python39-32\lib\site-packages\frontend\server.py", line 24, in
app.mount(config.STATIC_ROUTE, StaticFiles(directory=config.STATIC_DIRECTORY), name=config.STATIC_NAME)
File "C:\Users\刘旱雨\AppData\Local\Programs\Python\Python39-32\lib\site-packages\starlette\staticfiles.py", line 53, in init
raise RuntimeError(f"Directory '{directory}' does not exist")
RuntimeError: Directory 'static/' does not exist
试图重新安装pdf2docx 和Converter库,卸载和重新安装了几次,还是不成功。
程序能正常运行。
已解决,是版本问题,原来用的32位的,64位的python就可以了。
蛋疼啊, 我也在这个问题上面卡主了,
直接调用官方的指令也不行
from pdf2docx import Converter
# from pdf2docx import parse
m = 'test1.pdf'
n = 'test2.docx'
# convert pdf to docx
cv = Converter(m)
cv.convert(n) # all pages by default
cv.close()
看起来像是库出了问题
直接开python
输入这条语句,回车,看会出错吗?
from pdf2docx import Converter