Py2app - Add "from x import y" to setup.py
<p>I am using py2app to create a standalone APP from a python script however I have run into a problem which I am hoping you could help with.</p>

<p>The script relies heavily on tkinter, primarily the tkinter messagebox module, which is not imported with tkinter but rather has to be imported separately using:</p>

<pre><code>from tkinter import messagebox
</code></pre>

<p>In my setup.py file that I use to create the application, I have included all the modules that are used in the python, using this code:</p>

<pre><code>from setuptools import setup


APP = ['ch.py']
DATA_FILES = ['company.txt']
OPTIONS = {'argv_emulation': False, 'includes':['tkinter', 'requests', 'os'], 'iconfile': 'icon.icns'}

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

<p>However when I compile the app, everything works perfect except the tkinter messageboxes, which simply don't open. I know this is because I have not specifically imported them in the setup.py file.</p>

<p>Does anyone know how I can tell the setup.py file to include "from tkinter import messagebox?  </p>

<p>Many thanks!</p>

<p>Found an answer after about a day of searching, basically the problem isn't with the tkinter messagebox module. The problem was with the requests module that was used to contact the API which then returned information to be displayed in the messagebox. That is why the messagebox wasnt showing, because no request to the API was being made. </p>

<p>To fix this you need to add the requests module to 'packages' as well as 'includes', like follows:</p>

<pre><code>OPTIONS = {'argv_emulation': False, 'includes':['datetime', 'tkinter', 'requests'], 'packages':['requests'], 'iconfile':'icon.icns'}
</code></pre>

<p>Hope this helps anyone in the same scenario</p>

python tkinter py2app