在 python 脚本中调用时,pdftotext 找不到任何要转换的文件
我有一个 python 脚本,它不断崩溃:
subprocess.call(["pdftotext", pdf_filename])
错误是:
OSError: [Errno 2] No such file or directory
文件名的绝对路径(我在调试时将其存储在日志文件中)很好;在命令行上,如果我输入 pdftotext
它适用于任何据称错误的文件名。但是当在 python 中使用 subprocess
调用时,我不断收到该错误。
到底是怎么回事???
另外,我尝试了 python 解释器,它成功了!
>>> import subprocess
>>> subprocess.call(["pdftotext", "/path/to/file/test.pdf"])
0
>>>
更新:只是为了让大家都知道,我也尝试过:
subprocess.call(["/usr/bin/pdftotext", "/path/to/file/test.pdf"])
这也给出了同样的错误。我直接使用了 /usr/bin/pdftotext test.pdf
并且它有效,所以我知道这是 pdftotext 可执行文件的正确路径。还有其他建议吗?
i have a python script which keeps crashing on:
subprocess.call(["pdftotext", pdf_filename])
the error being:
OSError: [Errno 2] No such file or directory
the absolute path to the filename (which i am storing in a log file as i debug) is fine; on the command line, if i type pdftotext <pdf_filename_goes_here>
it works for any of the alledgedly bad file names. but when called using subprocess
in python i keep getting that error.
what is going on???
also, i tried on the python interpreter, and it worked!
>>> import subprocess
>>> subprocess.call(["pdftotext", "/path/to/file/test.pdf"])
0
>>>
update: just to make it known to everyone, i also tried:
subprocess.call(["/usr/bin/pdftotext", "/path/to/file/test.pdf"])
which also gave the same error. and ive used /usr/bin/pdftotext test.pdf
directly and it worked so i know that's the correct path to the pdftotext executable. any other suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果在路径上找不到可执行文件,您也会收到该错误...尝试使用 pdftotext 的完整路径,并查看 subprocess.call 的 $PATH 是如何设置的。
You'll also get that error if it can't find the executable on path...try using a full path to pdftotext as well, and look at how the $PATH for subprocess.call is set.