找不到wkhtmltopdf可执行文件

时间:2016-12-21 16:00:59

标签: python django wkhtmltopdf pdfkit

我尝试使用pdfkit librarywkhtmltopdf从我的HTML模板中获取PDF文件,但是我收到错误,而且我在Stackoverflow上找不到任何解决方案。

我读了这个主题:Can't create pdf using python PDFKIT Error : " No wkhtmltopdf executable found:"

但暂时没有......

我尝试了两件事:

def BirthCertificate_PDF(request, id) :

    birthcertificate = get_object_or_404(BirthCertificate, pk=id)
    pdfkit.from_file('BC_raw.html','test.pdf')
    return render(request, 'BC_raw.html', {"birthcertificate" : birthcertificate})

def BirthCertificate_PDF(request, id) :

    birthcertificate = get_object_or_404(BirthCertificate, pk=id)

    path_wkhtmltopdf = r'/usr/local/lib/python2.7/site-packages/wkhtmltopdf'
    config = pdfkit.configuration(wkhtmltopdf = path_wkhtmltopdf)
    pdfkit.from_file('BC_raw.html','test.pdf', configuration = config)

    return render(request, 'BC_raw.html', {"birthcertificate" : birthcertificate})

我每次都会收到此错误:

Exception Value:    
No wkhtmltopdf executable found: "/usr/local/lib/python2.7/site-packages/wkhtmltopdf"
If this file exists please check that this process can read it.

我做了:chmod 755但仍然没有。

你有解决方案吗?

编辑:

我发了ls -lth命令:

MacBook-Pro-de-Valentin:site-packages valentinjungbluth$ ls -lth
total 8864
drwxr-xr-x   12 valentinjungbluth  admin   408B 21 déc 16:22 pdfkit
drwxr-xr-x   10 valentinjungbluth  admin   340B 21 déc 16:22 pdfkit-0.6.0.dist-info
drwxr-xr-x   11 valentinjungbluth  admin   374B 21 déc 16:22 wkhtmltopdf
drwxr-xr-x    9 valentinjungbluth  admin   306B 21 déc 16:22 wkhtmltopdf-0.2.dist-info
drwxr-xr-x   14 valentinjungbluth  admin   476B 20 déc 12:06 pyPdf
drwxr-xr-x    9 valentinjungbluth  admin   306B 20 déc 12:06 pyPdf-1.13.dist-info
drwxr-xr-x   20 valentinjungbluth  admin   680B 20 déc 12:06 PyPDF2
drwxr-xr-x    9 valentinjungbluth  admin   306B 20 déc 12:06 PyPDF2-1.26.0.dist-info
drwxr-xr-x   23 valentinjungbluth  admin   782B 20 déc 12:06 html5lib
drwxr-xr-x    9 valentinjungbluth  admin   306B 20 déc 12:06 html5lib-0.999999999.dist-info
drwxr-xr-x   12 valentinjungbluth  admin   408B 20 déc 12:06 webencodings
drwxr-xr-x    9 valentinjungbluth  admin   306B 20 déc 12:06 webencodings-0.5.dist-info
drwxr-xr-x   54 valentinjungbluth  admin   1,8K 20 déc 12:06 xhtml2pdf
drwxr-xr-x   10 valentinjungbluth  admin   340B 20 déc 12:06 xhtml2pdf-0.0.6.dist-info
-rw-r--r--    1 valentinjungbluth  admin   1,5K 20 déc 12:06 sitecustomize.pyo
drwxr-xr-x   14 valentinjungbluth  admin   476B 20 déc 12:00 reportlab
drwxr-xr-x    9 valentinjungbluth  admin   306B 20 déc 12:00 reportlab-3.3.0.dist-info
drwxr-xr-x  189 valentinjungbluth  admin   6,3K 20 déc 12:00 PIL
drwxr-xr-x   10 valentinjungbluth  admin   340B 20 déc 12:00 Pillow-3.4.2.dist-info
drwxr-xr-x  149 valentinjungbluth  admin   4,9K 14 déc 17:32 matplotlib
drwxr-xr-x   10 valentinjungbluth  admin   340B 14 déc 17:32 matplotlib-1.5.3.dist-info
drwxr-xr-x   11 valentinjungbluth  admin   374B 14 déc 17:32 mpl_toolkits
-rw-r--r--    1 valentinjungbluth  admin   292B 14 déc 17:32 pylab.pyc
drwxr-xr-x    9 valentinjungbluth  admin   306B 14 déc 17:32 cycler-0.10.0.dist-info
-rw-r--r--    1 valentinjungbluth  admin    19K 14 déc 17:32 cycler.pyc
drwxr-xr-x   18 valentinjungbluth  admin   612B 14 déc 17:32 dateutil
drwxr-xr-x    9 valentinjungbluth  admin   306B 14 déc 17:32 pyparsing-2.1.10.dist-info
-rw-r--r--    1 valentinjungbluth  admin   241K 14 déc 17:32 pyparsing.pyc
drwxr-xr-x   10 valentinjungbluth  admin   340B 14 déc 17:32 python_dateutil-2.6.0.dist-info
drwxr-xr-x   15 valentinjungbluth  admin   510B 14 déc 17:32 pytz
drwxr-xr-x   10 valentinjungbluth  admin   340B 14 déc 17:32 pytz-2016.10.dist-info
-rw-r--r--    1 valentinjungbluth  admin    16K 14 déc 17:32 cycler.py
-rw-r--r--    1 valentinjungbluth  admin   323B 14 déc 17:32 matplotlib-1.5.3-py2.7-nspkg.pth
-rw-r--r--    1 valentinjungbluth  admin    90B 14 déc 17:32 pylab.py
-rw-r--r--    1 valentinjungbluth  admin   224K 14 déc 17:32 pyparsing.py
-rwxr-xr-x    1 root               admin   3,6M 14 déc 16:54 cv2.so
drwxr-xr-x    6 valentinjungbluth  admin   204B 14 déc 15:39 TBB-0.1-py2.7.egg-info
lrwxr-xr-x    1 valentinjungbluth  admin    67B 14 déc 15:39 TBB.py -> ../../../Cellar/tbb/4.4-20161004/lib/python2.7/site-packages/TBB.py
lrwxr-xr-x    1 valentinjungbluth  admin    68B 14 déc 15:39 _TBB.so -> ../../../Cellar/tbb/4.4-20161004/lib/python2.7/site-packages/_TBB.so
drwxr-xr-x   34 valentinjungbluth  admin   1,1K 14 déc 15:36 pip
drwxr-xr-x   10 valentinjungbluth  admin   340B 14 déc 15:36 pip-9.0.1.dist-info
-rw-r--r--    1 valentinjungbluth  admin    10K 14 déc 15:36 clonevirtualenv.py
-rw-r--r--    1 valentinjungbluth  admin    12K 14 déc 15:36 clonevirtualenv.pyc
drwxr-xr-x   23 valentinjungbluth  admin   782B 14 déc 15:36 stevedore
drwxr-xr-x   11 valentinjungbluth  admin   374B 14 déc 15:36 stevedore-1.19.1.dist-info
drwxr-xr-x   10 valentinjungbluth  admin   340B 14 déc 15:36 virtualenv-15.1.0.dist-info
-rw-r--r--    1 valentinjungbluth  admin    89K 14 déc 15:36 virtualenv.pyc
drwxr-xr-x   10 valentinjungbluth  admin   340B 14 déc 15:36 virtualenv_clone-0.2.6.dist-info
drwxr-xr-x    8 valentinjungbluth  admin   272B 14 déc 15:36 virtualenv_support
drwxr-xr-x    8 valentinjungbluth  admin   272B 14 déc 15:36 virtualenvwrapper
-rw-r--r--    1 valentinjungbluth  admin   338B 14 déc 15:36 virtualenvwrapper-4.7.2-py2.7-nspkg.pth
drwxr-xr-x   13 valentinjungbluth  admin   442B 14 déc 15:36 virtualenvwrapper-4.7.2.dist-info
-rw-r--r--    1 valentinjungbluth  admin    97K 14 déc 15:36 virtualenv.py
drwxr-xr-x   32 valentinjungbluth  admin   1,1K 14 déc 15:35 wheel
drwxr-xr-x    9 valentinjungbluth  admin   306B 14 déc 15:35 wheel-0.29.0-py2.7.egg-info
drwxr-xr-x   44 valentinjungbluth  admin   1,5K 14 déc 15:35 setuptools
drwxr-xr-x    9 valentinjungbluth  admin   306B 14 déc 15:35 setuptools-23.1.0-py2.7.egg-info
-rw-r--r--    1 valentinjungbluth  admin   321B 14 déc 15:35 easy_install.pyc
drwxr-xr-x    6 valentinjungbluth  admin   204B 14 déc 15:35 pkg_resources
-rw-r--r--    1 valentinjungbluth  admin   2,6K 14 déc 15:35 sitecustomize.py
-rw-r--r--    1 valentinjungbluth  admin   1,5K 14 déc 15:35 sitecustomize.pyc
-rw-r--r--    1 valentinjungbluth  admin   126B 25 jui 23:49 easy_install.py

1 个答案:

答案 0 :(得分:1)

我找到了解决方案,感谢@Hackerman @yorodm和@moopet:

我必须安装二进制文件(MacOSX版本):

wkhtmltopdf Binary paquet

现在有效!