Problems when using py2app to freeze a python script which uses pdfkit
<p>I recently created an application using pdfkit that takes a keyword entered by the user and makes various internet searches using that keyword. It then uses pdfkit to generate pdf files of each of the separate searches and saves them to a user-defined directory.</p>

<p>Everything works dandy when I run the code from terminal, however when I attempt to freeze the script using py2app, everything works fine up until it comes to actually saving the pdf's, at which the application does absolutely nothing. </p>

<p>I have tried to include both pdfkit and wkhtmltopdf in the setup.py file which py2app uses to create the application, but to no luck, I have tried listing them under the includes section like this:</p>

<pre><code>'includes':['requests','pdfkit']
</code></pre>

<p>In the packages section:</p>

<pre><code>'packages':['requests','pdfkit']
</code></pre>

<p>and even in the setup_requires section below:</p>

<pre><code>setup_requires=['py2app', 'wkhtmltopdf']
</code></pre>

<p>But still the application does nothing. I presume its something to do with the fact that a dependency doesn't get carried over to the frozen application. However I am starting to rethink this as even when I create the app in alias mode (which claims to keep all dependencies), the same problem occurs.</p>

<p>Is this a known issue? Or has anyone found out a solution to this.</p>

<p>Many thanks. My full setup.py file is below:</p>

<pre><code>    from setuptools import setup

APP = ['pdtest.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': False, 'includes':['requests','pdfkit'],'packages':['requests','pdfkit'], 'iconfile':'icon.icns'}

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app', 'wkhtmltopdf'],
)
</code></pre>

<p>Ok found an answer so anyone who is having the same problem can use it.</p>

<p>Basically the problem lies in the fact that pdfkit is just a wrapper for the module WKHTMLTOPDF. </p>

<p>So basically all that happens when you call on PDFKIT is that it just asks WKHTMLTOPDF to do the work for it, however on my system for some reason, the script was able to find the WKHTMLTOPDF module when it was being ran from terminal, but was unable to when converted into an applet using py2app.</p>

<p>What I needed to do was tell the script exactly where WKHTMLTOPDF was located, but first you need to know that information yourself, just type into terminal:</p>

<pre><code>which wkhtmltopdf
</code></pre>

<p>and you should get a path returned. If you don't then maybe you should think about installing it first, that usually helps.</p>

<p>Then you need to set the configuration file to look in that place for the wkhtmltopdf module, so just add this to your pdfkit script:</p>

<pre><code>config = pdfkit.configuration(wkhtmltopdf='/usr/local/bin/wkhtmltopdf')
</code></pre>

<p>Except replace the path after the "=' with whatever path the earlier which command returned. Then, everytime you call on pdfkit, you need to add this configuration, for example:</p>

<pre><code>normalpdf = pdfkit.from_url('URL, 'test.pdf',configuration = config)
</code></pre>

<p>And that should solve the issue. Hope it helps!</p>

python py2app python-pdfkit