python – wkhtmltopdf错误“没有这样的文件或目录”(Django)
作者:互联网
我正在尝试使用wkhtmltopdf从HTML代码创建PDF.我使用过xhtml2pdf和pisa但是我遇到了css样式的问题.好吧,wkhtmltopdf是我的最后一个选择.
我已经按照这个步骤. https://github.com/incuna/django-wkhtmltopdf
sudo aptitude install libfontconfig
pip install django-wkhtmltopdf
如果我将’wkhtmltopdf’添加到我的INSTALLED_APPS,它将识别wkhtmltopdf路径.
INSTALLED_APPS = ["wkhtmltopdf"]
好吧,当我尝试生成PDF时会产生错误.
这是我的代码:
from wkhtmltopdf.views import PDFTemplateResponse
context = {
'linkedin1':self.linkedin1,
'twitter1':self.twitter1,
'facebook1':self.facebook1,
'current': get_current_base_url,
}
html_path = "app/folder/page1_1.html"
response = PDFTemplateResponse(request=request,
template=html_path,
filename="hello.pdf",
context= context,
show_content_in_browser=False,
cmd_options=settings.WKHTMLTOPDF_CMD_OPTIONS,
)
在设置中:
WKHTMLTOPDF_CMD_OPTIONS = {
'quiet': True,
}
我的错误:
File "/home/user/.virtualenvs/app/local/lib/python2.7/site- packages/django/core/handlers/base.py", line 136, in get_response
response = response.render()
File "/home/user/.virtualenvs/app/local/lib/python2.7/site-packages/django/template/response.py", line 104, in render
self._set_content(self.rendered_content)
File "/home/user/.virtualenvs/app/local/lib/python2.7/site- packages/wkhtmltopdf/views.py", line 144, in rendered_content
footer_filename=footer_filename)
File "/home/user/.virtualenvs/app/local/lib/python2.7/site-packages/wkhtmltopdf/views.py", line 103, in convert_to_pdf
return wkhtmltopdf(pages=[filename], **cmd_options)
File "/home/user/.virtualenvs/app/local/lib/python2.7/site-packages/wkhtmltopdf/utils.py", line 92, in wkhtmltopdf
return check_output(ck_args, **ck_kwargs)
File "/usr/lib/python2.7/subprocess.py", line 537, in check_output
process = Popen(stdout=PIPE, *popenargs, **kwargs)
File "/usr/lib/python2.7/subprocess.py", line 679, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1259, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
我认为它找不到’wkhtmltopdf’.
我的wkhtmltopdf安装路径是:
/home/user/.virtualenvs/app/local/lib/python2.7/site-packages/wkhtmltopdf/
好吧,我添加设置:
WKHTMLTOPDF_CMD = '/home/user/.virtualenvs/app/local/lib/python2.7/site-packages/wkhtmltopdf/'
找到wkhtmltopdf和上诉“路径权限被拒绝”
有什么不对?缺少什么?,问题是什么?
我在用:
Ububtu服务器12.04 / 64位,
Django 1.4,
Pyrhon 2.7,
谢谢你的回答.
编辑1:
我按照本教程修复了mi问题
http://www.cristalab.com/tutoriales/crear-pdf-en-django-y-virtualenv-c110664l/
apt-get build-dep libqt4-gui libqt4-network libqt4-webkit
apt-get install openssl build-essential xorg git-core git-doc libssl-dev wkhtmltopdf
在设置中
WKHTMLTOPDF_CMD = "/usr/bin/wkhtmltopdf"
但是出现了新的错误:
File "/home/user/.virtualenvs/app/local/lib/python2.7/site- packages/django/template/response.py", line 104, in render
self._set_content(self.rendered_content)
File "/home/user/.virtualenvs/app/local/lib/python2.7/site- packages/wkhtmltopdf/views.py", line 144, in rendered_content
footer_filename=footer_filename)
File "/home/user/.virtualenvs/app/local/lib/python2.7/site-packages/wkhtmltopdf/views.py", line 103, in convert_to_pdf
return wkhtmltopdf(pages=[filename], **cmd_options)
File "/home/user/.virtualenvs/app/local/lib/python2.7/site-packages/wkhtmltopdf/utils.py", line 92, in wkhtmltopdf
return check_output(ck_args, **ck_kwargs)
File "/usr/lib/python2.7/subprocess.py", line 544, in check_output
raise CalledProcessError(retcode, cmd, output=output)
CalledProcessError: Command '['/usr/bin/wkhtmltopdf', '--encoding', u'utf8', '--quiet', '/tmp/wkhtmltopdfE_THjv.html', '-']' returned non-zero exit status
解决了:
———– 7月14日———–
0)创建一个〜/ tmp /目录并更改为它
cd ~
mkdir tmp
cd tmp
1)来自http://code.google.com/p/wkhtmltopdf/downloads/list的libwkhtmltox-0.11.0_rc1-amd64.tar.bz2和wkhtmltopdf-0.11.0_rc1-static-amd64.tar.bz2
wget https://wkhtmltopdf.googlecode.com/files/libwkhtmltox-0.11.0_rc1-amd64.tar.bz2
wget https://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.11.0_rc1-static-amd64.tar.bz2
2)创建子文件夹并将文件移入其中:
mkdir libwkhtmltox
mkdir wkhtmltopdf
mv libwkhtmltox-0.11.0_rc1-amd64.tar.bz2 libwkhtmltox
mv wkhtmltopdf-0.11.0_rc1-static-amd64.tar.bz2 wkhtmltopdf
3)进入以前创建的文件夹并解压缩文件.
cd libwkhtmltox
tar -xvjf libwkhtmltox-0.11.0_rc1-amd64.tar.bz2
cd ../wkhtmltopdf
tar -xvjf wkhtmltopdf-0.11.0_rc1-static-amd64.tar.bz2
4)访问’lib’.在那里我们找到一个名为’libwkhtmltox.so’的文件,然后移动它
cd ../libwkhtmltox/lib/
sudo cp libwkhtmltox.so /usr/local/lib/
5)访问include,在那里我们找到一个名为’wkhtmltox’的文件夹,然后移动它
cd ../include/
sudo cp -avr wkhtmltox/ /usr/local/include/
6)解压缩文件后我们找到文件“wkhtmltopdf-amd64”,移动它.
cd ../../wkhtmltopdf/
sudo cp wkhtmltopdf-amd64 /usr/bin/
7)我正在关注这篇文章. http://www.cristalab.com/tutoriales/crear-pdf-en-django-y-virtualenv-c110664l/
8)安装
sudo aptitude install libfontconfig
sudo apt-get build-dep libqt4-gui libqt4-network libqt4-webkit
sudo apt-get install openssl build-essential xorg git-core git-doc libssl-dev wkhtmltopdf
9)我正在关注这篇文章,https://github.com/incuna/django-wkhtmltopdf
10)以后安装应用程序
pip install django-wkhtmltopdf
解决方法:
我按照以下步骤解决了这个问题:
0)创建一个〜/ tmp /目录并更改为它
cd ~
mkdir tmp
cd tmp
1)来自http://code.google.com/p/wkhtmltopdf/downloads/list的libwkhtmltox-0.11.0_rc1-amd64.tar.bz2和wkhtmltopdf-0.11.0_rc1-static-amd64.tar.bz2
wget https://wkhtmltopdf.googlecode.com/files/libwkhtmltox-0.11.0_rc1-amd64.tar.bz2
wget https://wkhtmltopdf.googlecode.com/files/wkhtmltopdf-0.11.0_rc1-static-amd64.tar.bz2
2)创建子文件夹并将文件移入其中:
mkdir libwkhtmltox
mkdir wkhtmltopdf
mv libwkhtmltox-0.11.0_rc1-amd64.tar.bz2 libwkhtmltox
mv wkhtmltopdf-0.11.0_rc1-static-amd64.tar.bz2 wkhtmltopdf
3)进入以前创建的文件夹并解压缩文件.
cd libwkhtmltox tar -xvjf libwkhtmltox-0.11.0_rc1-amd64.tar.bz2
cd ../wkhtmltopdf tar -xvjf wkhtmltopdf-0.11.0_rc1-static-amd64.tar.bz2
4)访问’lib’.在那里我们找到一个名为’libwkhtmltox.so’的文件,然后移动它
cd ../libwkhtmltox/lib/
sudo cp libwkhtmltox.so /usr/local/lib/
5)访问include,在那里我们找到一个名为’wkhtmltox’的文件夹,然后移动它
cd ../include/
sudo cp -avr wkhtmltox/ /usr/local/include/
6)解压缩文件后我们找到文件“wkhtmltopdf-amd64”,移动它.
cd ../../wkhtmltopdf/
sudo cp wkhtmltopdf-amd64 /usr/bin/
7)我正在关注这篇文章. http://www.cristalab.com/tutoriales/crear-pdf-en-django-y-virtualenv-c110664l/
8)安装
sudo aptitude install libfontconfig
sudo apt-get build-dep libqt4-gui libqt4-network libqt4-webkit
sudo apt-get install openssl build-essential xorg git-core git-doc libssl-dev wkhtmltopdf
9)我正在关注这篇文章,https://github.com/incuna/django-wkhtmltopdf
10)以后安装应用程序
pip install django-wkhtmltopdf
标签:python,django,wkhtmltopdf,pisa,xhtml2pdf 来源: https://codeday.me/bug/20190629/1323929.html