![](/img/trans.png)
[英]Chromedriver: "FileNotFoundError: [WinError 2] The system cannot find the file specified" Error
[英]FileNotFoundError: [WinError 2] The system cannot find the file specified.Error
import os
from pdf2image import convert_from_path
pdf_dir = (r"C:\Users\Dell\Desktop\Dataset\Test")
os.chdir(pdf_dir)
for pdf_file in os.listdir(r"C:\Users\Dell\Desktop\Dataset\Test"):
if pdf_file.endswith(".pdf"):
pages = convert_from_path(pdf_file, 300)
pdf_file = pdf_file[:-4]
for page in pages:
page.save("%s-page%d.jpg" % (pdf_file,pages.index(page)), "JPEG")
尝试在每一步添加打印语句进行调试,以准确查看哪些文件不存在/目录名称错误。 例如 -
for pdf_file in os.listdir(r"C:\Users\Dell\Desktop\Dataset\Test"):
print(pdf_file) ###1st step to see if your path contains relevant files
if pdf_file.endswith(".pdf"):
pages = convert_from_path(pdf_file, 300) ##If the error is at this line, try adding the complete path, rather than file name
pdf_file = pdf_file[:-4]
print(pdf_file) ## See what is the pdf file name extracted
for page in pages:
print(page) ## See whats the value of page generated
page.save("%s-page%d.jpg" % (pdf_file,pages.index(page)), "JPEG")
这是调试的基本思想,过去对我有帮助。 你的问题没有描述完整的错误,哪个文件不存在。 因此,通用方法。
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.