1

通过 py2app 后,我无法让 SQLAlchemy 与我编译的应用程序一起工作。我已经在 Windows 中使用 py2exe 成功完成了这项工作。以下是我的设置文件:

APP = ['Blah.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True,
           'includes': ['sip',
                        'PyQt4._qt',
                        'sqlalchemy.dialects.mysql',
                        'MySQLdb',
                        "gzip"]
           }

setup(
    app=APP,
    data_files=DATA_FILES,
    options={'py2app': OPTIONS},
    setup_requires=['py2app'],
)

这似乎是正确的方法,因为我已经看到人们将它用于 sqlite,但是在编译后尝试运行应用程序时我仍然收到此错误:

sqlalchemy.exc.ArgumentError: Could not determine dialect for 'mysql+mysqldb'

我最近一直在尝试使用 PyInstaller 并且几乎被困在同一个地方,尽管有一个不同的错误,如下所示:

 Traceback (most recent call last):
   File "<string>", line 96, in <module>
   File "/Users/tom/Downloads/pyinstaller-pyinstaller-2145d84/PyInstaller/loader/iu.py", line 386, in importHook
     mod = _self_doimport(nm, ctx, fqname)
   File "/Users/tom/Downloads/pyinstaller-pyinstaller-2145d84/PyInstaller/loader/iu.py", line 480, in doimport
     exec co in mod.__dict__
   File "build/bdist.macosx-10.7-intel/egg/MySQLdb/__init__.py", line 19, in <module>
   File "/Users/tom/Downloads/pyinstaller-pyinstaller-2145d84/PyInstaller/loader/iu.py", line 386, in importHook
     mod = _self_doimport(nm, ctx, fqname)
   File "/Users/tom/Downloads/pyinstaller-pyinstaller-2145d84/PyInstaller/loader/iu.py", line 480, in doimport
     exec co in mod.__dict__
   File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 7, in <module>
   File "build/bdist.macosx-10.7-intel/egg/_mysql.py", line 4, in __bootstrap__
   File "OSX_Installer/Jango/build/pyi.darwin/Jango/out00-PYZ.pyz/pkg_resources", line 882, in resource_filename
   File "OSX_Installer/Jango/build/pyi.darwin/Jango/out00-PYZ.pyz/pkg_resources", line 1352, in get_resource_filename
   File "OSX_Installer/Jango/build/pyi.darwin/Jango/out00-PYZ.pyz/pkg_resources", line 1363, in _extract_resource
 KeyError: '_mysql/_mysql.so'
4

1 回答 1

1

您可能还需要_mysql包含本机 mysql 绑定。此外,此绑定需要在目标系统上安装二进制 mysql 库。

如果您使用纯 python mysql 库,例如pymysqlMySQL Connector/Python(两者都受 sqlalchemy 支持),您的应用程序可能会更便携

于 2012-05-13T20:28:11.563 回答