python html如何轉成PDF?
問題描述
import pdfkitpdfkit.from_url(’http://www.cocoachina.com/’, ’out.pdf’)
老報錯我已經安裝了wkhtmltopdf :還請大神幫忙解決!
還有如何將wkhtmltopdf的執行路徑添加到系統環境$PATH變量中?
Traceback (most recent call last): File '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pdfkit/configuration.py', line 21, in __init__ with open(self.wkhtmltopdf) as f:FileNotFoundError: [Errno 2] No such file or directory: b’’During handling of the above exception, another exception occurred:Traceback (most recent call last): File '/Users/peibobo/PycharmProjects/bottle/pdf_test.py', line 3, in <module> pdfkit.from_url(’http://www.cocoachina.com/’, ’out.pdf’) File '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pdfkit/api.py', line 24, in from_url configuration=configuration, cover_first=cover_first) File '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pdfkit/pdfkit.py', line 42, in __init__ self.configuration = (Configuration() if configuration is None File '/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/pdfkit/configuration.py', line 27, in __init__ ’https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf’ % self.wkhtmltopdf)OSError: No wkhtmltopdf executable found: 'b’’'If this file exists please check that this process can read it. Otherwise please install wkhtmltopdf - https://github.com/JazzCore/python-pdfkit/wiki/Installing-wkhtmltopdf
問題解答
回答1:首先是你21行這句錯誤with open(self.wkhtmltopdf) as f:
應該是self.wkhtmltopdf為空字符串,沒有可以打開的文件
相關文章:
1. css - 新手做響應式布局, 斷點過后右側出現空白,求幫助,謝謝。2. javascript - 關于<a>元素與<input>元素的JS事件運行問題3. javascript - ES6 中能否把 class 屬性 方法 分文件?4. python - 能通過CAN控制一部普通的家用轎車嗎?5. mysql - 查詢字段做了索引為什么不起效,還有查詢一個月的時候數據都是全部出來的,如果分拆3次的話就沒問題,為什么呢。6. mysql - 記得以前在哪里看過一個估算時間的網站7. ID主鍵不是自增的嗎 為什么還要加null8. 大家好,我想請問一下怎么做搜索欄能夠搜索到自己網站的內容。9. MySQL中的enum類型有什么優點?10. css - 關于border-image
