py2app 问题,出现错误

py2app problems, getting errors

我正在尝试测试 py2app 的功能,以创建独立的 mac 应用程序。我为我的测试代码生成了一个设置文件,名为 'hello.py'.

"""
This is a setup.py script generated by py2applet

Usage:
python setup.py py2app
"""

from setuptools import setup

APP = ['hello.py']
DATA_FILES = []
OPTIONS = {'argv_emulation': True}

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

我正在尝试制作一个简单的应用程序,它只通过 GUI 向世界问好。这是 hello.py

的代码
import sys
from PyQt4 import QtGui
from PyQt4 import QtCore

app = QtGui.QApplication(sys.argv)

widget = QtGui.QLabel("Hello World")
widget.show()


app.exec_()

上面的脚本 运行 很好,但是当我尝试使用 py2app 时,出现了一些错误。当我运行'python setup.py py2app'

WARNING: ImportError in sip recipe ignored: No module named py2app-0
WARNING: ImportError in sip recipe ignored: No module named Sphinx-1
WARNING: ImportError in sip recipe ignored: No module named decorator-4
WARNING: ImportError in sip recipe ignored: No module named altgraph-0
WARNING: ImportError in sip recipe ignored: No module named matplotlib-1
WARNING: ImportError in sip recipe ignored: No module named alabaster-0
WARNING: ImportError in sip recipe ignored: No module named modulegraph-0
WARNING: ImportError in sip recipe ignored: No module named Jinja2-2
WARNING: ImportError in sip recipe ignored: No module named jedi-0
WARNING: ImportError in sip recipe ignored: No module named pickleshare-0
WARNING: ImportError in sip recipe ignored: No module named macholib-1
WARNING: ImportError in sip recipe ignored: No module named Babel-1
WARNING: ImportError in sip recipe ignored: No module named sphinx_rtd_theme-0
WARNING: ImportError in sip recipe ignored: No module named pip-7
WARNING: ImportError in sip recipe ignored: No module named wheel-0
WARNING: ImportError in sip recipe ignored: No module named python_dateutil-2

出现这些错误后,py2app 似乎 运行ning 正常,但应用程序本身当然无法正常工作。这里发生了什么?我该如何解决这个问题?

这也是终端输出的最后一行。

Traceback (most recent call last):
File "setup.py", line 18, in <module>
setup_requires=['py2app'],
File "/Users/Apollo/miniconda/lib/python2.7/distutils/core.py", line 151, in          setup
dist.run_commands()
File "/Users/Apollo/miniconda/lib/python2.7/distutils/dist.py", line 953, in   run_commands
self.run_command(cmd)
File "/Users/Apollo/miniconda/lib/python2.7/distutils/dist.py", line 972, in   run_command
cmd_obj.run()
File "/Users/Apollo/miniconda/lib/python2.7/site- packages/py2app/build_app.py", line 659, in run
self._run()
File "/Users/Apollo/miniconda/lib/python2.7/site-packages/py2app/build_app.py", line 865, in _run
self.run_normal()
File "/Users/Apollo/miniconda/lib/python2.7/site-packages/py2app/build_app.py", line 959, in run_normal
self.create_binaries(py_files, pkgdirs, extensions, loader_files)
File "/Users/Apollo/miniconda/lib/python2.7/site-packages/py2app/build_app.py", line 1214, in create_binaries
platfiles = mm.run()
File "/Users/Apollo/miniconda/lib/python2.7/site- packages/macholib/MachOStandalone.py", line 105, in run
mm.run_file(fn)
File "/Users/Apollo/miniconda/lib/python2.7/site-packages/macholib/MachOGraph.py", line 84, in run_file
self.scan_node(m)
File "/Users/Apollo/miniconda/lib/python2.7/site-packages/macholib/MachOGraph.py", line 110, in scan_node
m = self.load_file(filename, caller=node)
File "/Users/Apollo/miniconda/lib/python2.7/site-packages/macholib/MachOGraph.py", line 93, in load_file
newname = self.locate(name, loader=caller)
File "/Users/Apollo/miniconda/lib/python2.7/site-packages/macholib/MachOStandalone.py", line 23, in locate
newname = super(FilteredMachOGraph, self).locate(filename, loader)
File "/Users/Apollo/miniconda/lib/python2.7/site-packages/macholib/MachOGraph.py", line 49, in locate
loader=loader.filename)
TypeError: dyld_find() got an unexpected keyword argument 'loader'

有一个小技巧可以解决这个问题,

  1. 转到您的路径 /Users/Apollo/miniconda/lib/python2.7/site-packages/macholib/MachOGraph.py 并打开此文件。
  2. 在第 49 行,将 loader=loader.filename 更改为 loader_path=loader.filename

运行 再次 setup.py。