How do I use py2app with Anaconda python?

試著忘記壹切 提交于 2019-12-01 08:26:23

The suggestion by @l'L'l allowed me to identify the problem: While there were no errors when I generated my app in "alias mode" (using symlinks to the environment instead of copying binaries), building the app without alias mode flushed out the error: py2app looks for the libpython DLL under the non-existent name /Applications/anaconda/lib/libpython3.4.dylib.

A quick check showed that Anaconda provides this DLL under a slightly different name: libpython3.4m.dylib. While patching dist/my-script.app/Contents/Info.plist fixes the problem, the right solution is to edit setup.py so that future builds will work correctly. With the help of the py2app documentation, I put together the following (partial contents of setup.py shown):

OPTIONS = {'argv_emulation': True,
           'plist': {
               'PyRuntimeLocations': [
                '@executable_path/../Frameworks/libpython3.4m.dylib',
                '/Applications/anaconda/lib/libpython3.4m.dylib'
               ]
           }}

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

The paths come from the generated Info.plist; I only modified the absolute path, reasoning that if I ever provide a local DLL at the relative path, it will have the default name.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!