I'm trying to package an app and include pymssql
with it.
Here's my setup.py:
"""
This is a setup.py script generated by py2applet
Usage:
python setup.py py2app
"""
from setuptools import setup
APP = ['AppName.py']
DATA_FILES = ['pic1.jpg', 'pic2.jpeg']
OPTIONS = {'argv_emulation': True,
'packages': ['tkinter', '_mssql', 'pymssql']
}
setup(
app=APP,
data_files=DATA_FILES,
options={'py2app': OPTIONS},
setup_requires=['py2app'],
)
When I only include _mssql
it gives this error:
error: cannot copy tree '/path_to_venv/lib/python3.4/site-packages/_mssql.so': not a directory
When I try with pymssql
(or both) it gives this error:
Traceback (most recent call last):
File "setup.py", line 20, in <module>
setup_requires=['py2app'],
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/core.py", line 148, in setup
dist.run_commands()
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/path_to_venv/lib/python3.4/site-packages/py2app/build_app.py", line 659, in run
self._run()
File "/path_to_venv/lib/python3.4/site-packages/py2app/build_app.py", line 865, in _run
self.run_normal()
File "/path_to_venv/lib/python3.4/site-packages/py2app/build_app.py", line 939, in run_normal
mf = self.get_modulefinder()
File "/path_to_venv/lib/python3.4/site-packages/py2app/build_app.py", line 814, in get_modulefinder
debug=debug,
File "/path_to_venv/lib/python3.4/site-packages/modulegraph/find_modules.py", line 341, in find_modules
find_needed_modules(mf, scripts, includes, packages)
File "/path_to_venv/lib/python3.4/site-packages/modulegraph/find_modules.py", line 266, in find_needed_modules
path = m.packagepath[0]
TypeError: 'NoneType' object is not subscriptable
Another note:
I can package the app fine without including either pymssql
or _mssql
in the setup file and when I try and run the app, here's the error I get in the OS Console:
1/12/16 10:00:48.618 AM AppName[72301]: Traceback (most recent call last):
1/12/16 10:00:48.618 AM AppName[72301]: File "/path_to_app/dist/AppName.app/Contents/Resources/__boot__.py", line 351, in <module>
1/12/16 10:00:48.618 AM AppName[72301]: _run()
1/12/16 10:00:48.619 AM AppName[72301]: File "/path_to_app/dist/AppName.app/Contents/Resources/__boot__.py", line 336, in _run
1/12/16 10:00:48.619 AM AppName[72301]: exec(compile(source, path, 'exec'), globals(), globals())
1/12/16 10:00:48.619 AM AppName[72301]: File "/path_to_app/dist/AppName.app/Contents/Resources/AppName.py", line 9, in <module>
1/12/16 10:00:48.619 AM AppName[72301]: import pymssql
1/12/16 10:00:48.619 AM AppName[72301]: File "_mssql.pxd", line 10, in init pymssql (pymssql.c:10984)
1/12/16 10:00:48.619 AM AppName[72301]: ImportError: No module named '_mssql'
I figured out a workaround. Probably not the best way, but it works now.
I added import _mssql
into my main app script (already had import pymssql
).
I then took my _mssql.pyx
file and put a copy in my app dir.
I added _mssql.pyx
under the DATA_FILES
in the setup.py
file.
You will need to include decimal
and uuid
into your setup.py
file if not already included somewhere else.
Leave pymssql
and _mssql
out of the packages
list in the setup.py
file as py2app
will find them and include them automatically.
You may need to include other libraries that the _mssql.pyx
file will try and import. Just keep adding them until it works.