No wkhtmltopdf executable found

2.1k views Asked by At

I'm trying to get a PDF file from my HTML template using pdfkit library and wkhtmltopdf but I get an error and I don't find any solutions on Stackoverflow.

I read this topic : Can't create pdf using python PDFKIT Error : " No wkhtmltopdf executable found:"

But nothing for the moment ...

I tried two things :

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})

and

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})

And I get this error each time :

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.

I made : chmod 755 but still nothing.

Do you have a solution ?

EDIT :

I made ls -lth command :

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

There are 1 answers

0
Essex On BEST ANSWER

I found the solution thanks to @Hackerman @yorodm and @moopet :

I have to install binary file (MacOSX version) :

wkhtmltopdf Binary paquet

Now it works !