在 py2app 中包含 pymssql
Include pymssql in py2app
我正在尝试打包应用程序并将 pymssql
包含在其中。
这是我的 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'],
)
当我只包含 _mssql
时,它给出了这个错误:
error: cannot copy tree '/path_to_venv/lib/python3.4/site-packages/_mssql.so': not a directory
当我尝试使用 pymssql
(或两者)时,出现此错误:
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
另注:
我可以很好地打包应用程序,而无需在安装文件中包含 pymssql
或 _mssql
,当我尝试 运行 应用程序时,这是我在 OS 控制台:
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'
我找到了解决方法。可能不是最好的方法,但现在可以了。
我将 import _mssql
添加到我的主应用程序脚本中(已经有 import pymssql
)。
然后我拿了我的 _mssql.pyx
文件并在我的应用程序目录中复制了一份。
我在 setup.py
文件的 DATA_FILES
下添加了 _mssql.pyx
。
您需要将 decimal
和 uuid
添加到您的 setup.py
文件中(如果其他地方尚未包含)。
将 pymssql
和 _mssql
留在 setup.py
文件的 packages
列表之外,因为 py2app
会自动找到并包含它们。
您可能需要包含 _mssql.pyx
文件将尝试导入的其他库。继续添加它们直到它起作用。
我正在尝试打包应用程序并将 pymssql
包含在其中。
这是我的 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'],
)
当我只包含 _mssql
时,它给出了这个错误:
error: cannot copy tree '/path_to_venv/lib/python3.4/site-packages/_mssql.so': not a directory
当我尝试使用 pymssql
(或两者)时,出现此错误:
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
另注:
我可以很好地打包应用程序,而无需在安装文件中包含 pymssql
或 _mssql
,当我尝试 运行 应用程序时,这是我在 OS 控制台:
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'
我找到了解决方法。可能不是最好的方法,但现在可以了。
我将 import _mssql
添加到我的主应用程序脚本中(已经有 import pymssql
)。
然后我拿了我的 _mssql.pyx
文件并在我的应用程序目录中复制了一份。
我在 setup.py
文件的 DATA_FILES
下添加了 _mssql.pyx
。
您需要将 decimal
和 uuid
添加到您的 setup.py
文件中(如果其他地方尚未包含)。
将 pymssql
和 _mssql
留在 setup.py
文件的 packages
列表之外,因为 py2app
会自动找到并包含它们。
您可能需要包含 _mssql.pyx
文件将尝试导入的其他库。继续添加它们直到它起作用。