Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在Mac上使用cx_freeze(或Py2App)创建独立python/Qt应用程序失败_Python_Macos_Qt_Cx Freeze_Py2app - Fatal编程技术网

在Mac上使用cx_freeze(或Py2App)创建独立python/Qt应用程序失败

在Mac上使用cx_freeze(或Py2App)创建独立python/Qt应用程序失败,python,macos,qt,cx-freeze,py2app,Python,Macos,Qt,Cx Freeze,Py2app,在使用cx_freeze和Py2App时,我很难从基于python Qt的程序为Mac创建独立的应用程序。(请注意,我在使用cx_freeze的Windows上成功地完成了此操作) 实际上,cx_freeze提供的“PyQt4”示例在Mac上无法正常运行。有人能在Mac上“构建”并运行这个示例吗?!我在论坛上找不到关于这个看似基本的问题的任何信息 事实上,让我们首先建设: ~$ cd cx_Freeze-4.3.3/cx_Freeze/samples/PyQt4/ PyQt4$ ls P

在使用cx_freeze和Py2App时,我很难从基于python Qt的程序为Mac创建独立的应用程序。(请注意,我在使用cx_freeze的Windows上成功地完成了此操作)

实际上,cx_freeze提供的“PyQt4”示例在Mac上无法正常运行。有人能在Mac上“构建”并运行这个示例吗?!我在论坛上找不到关于这个看似基本的问题的任何信息

事实上,让我们首先建设:

~$ cd cx_Freeze-4.3.3/cx_Freeze/samples/PyQt4/
PyQt4$ ls
    PyQt4app.py setup.py
PyQt4$ python setup.py build
    running build
    running build_exe
    creating directory build/exe.macosx-10.5-x86_64-2.7
    copying //anaconda/lib/python2.7/site-packages/cx_Freeze-4.3.3-py2.7-
    macosx-10.5-x86_64.egg/cx_Freeze/bases/Console -> build/exe.macosx-10.5-x86_64-2.7/PyQt4app
    TD bug fix: adding //anaconda/lib to relative path libpython2.7.dylib!
    copying //anaconda/lib/libpython2.7.dylib -> build/exe.macosx-10.5-x86_64-2.7/libpython2.7.dylib
    TD bug fix: adding //anaconda/lib to relative path libpython2.7.dylib!
    writing zip file build/exe.macosx-10.5-x86_64-2.7/library.zip
    …
    copying //anaconda/lib/python2.7/lib-dynload/zlib.so -> build/exe.macosx-10.5-x86_64-2.7/zlib.so
PyQt4$
注意“TD bug fix…”行:为了在没有“file not found”错误的情况下运行上述程序,我必须在cx_freeze file
freezer.py
中添加对函数
\u getDependentFile
的更正:

for i in range(len(dependentFiles)):
    filei = dependentFiles[i]
    if not os.path.isabs(filei):
        print 'TD bug fix: adding ' + sys.prefix + '/lib to relative path ' + filei + '!'
        dependentFiles[i] = os.path.join(sys.prefix,'lib',filei)
现在,当尝试运行创建的独立程序时,我得到:

PyQt4$ ls
    PyQt4app.py  build  setup.py
PyQt4$ cd build/exe.macosx-10.5-x86_64-2.7/
exe.macosx-10.5-x86_64-2.7$ ls
    PyQt4.QtCore.so _codecs_iso2022.so _struct.so   libQtCore.dylib    libz.1.dylib
    PyQt4.QtGui.so  _codecs_jp.so      binascii.so  libQtGui.4.dylib   sip.so
    PyQt4app        _codecs_kr.so      bz2.so       libQtGui.dylib     unicodedata.so
    _codecs_cn.so   _codecs_tw.so      itertools.so libpython2.7.dylib zlib.so
    _codecs_hk.so   _multibytecodec.so libQtCore.4.dylib library.zip
exe.macosx-10.5-x86_64-2.7$ ./PyQt4app
    Traceback (most recent call last):
      File "//anaconda/lib/python2.7/site-packages/cx_Freeze-4.3.3-py2.7-macosx-10.5-x86_64.egg/cx_Freeze/initscripts/Console.py", line 27, in <module>
        exec(code, m.__dict__)
      File "PyQt4app.py", line 5, in <module>
      File "ExtensionLoader_PyQt4_QtGui.py", line 22, in <module>
      File "ExtensionLoader_PyQt4_QtGui.py", line 14, in __bootstrap__
    ImportError: dlopen(/Users/thomasdeneux/cx_Freeze-4.3.3/cx_Freeze/samples/PyQt4/build/exe.macosx-10.5-x86_64-2.7/PyQt4.QtGui.so, 2): Library not loaded: @loader_path/../../../libQtGui.4.dylib
      Referenced from: /Users/thomasdeneux/cx_Freeze-4.3.3/cx_Freeze/samples/PyQt4/build/exe.macosx-10.5-x86_64-2.7/PyQt4.QtGui.so
      Reason: image not found
exe.macosx-10.5-x86_64-2.7$
PyQt4$ls
PyQt4app.py build setup.py
PyQt4$cd build/exe.macosx-10.5-x86_64-2.7/
exe.macosx-10.5-x86_64-2.7$ls
PyQt4.QtCore.so_codecs_iso2022.so_struct.so libQtCore.dylib libz.1.dylib
PyQt4.QtGui.so_codecs_jp.so binascii.so libQtGui.4.dylib sip.so
PyQt4app_编解码器_kr.so bz2.so libQtGui.dylib unicodedata.so
_codecs\u cn.so\u codecs\u tw.so itertools.so libpython2.7.dylib zlib.so
_codecs_hk.so_multibytecodec.so libQtCore.4.dylib library.zip
exe.macosx-10.5-x86_64-2.7$./PyQt4app
回溯(最近一次呼叫最后一次):
文件“//anaconda/lib/python2.7/site packages/cx_Freeze-4.3.3-py2.7-macosx-10.5-x86_64.egg/cx_Freeze/initscripts/Console.py”,第27行
执行官(代码、指令)
文件“PyQt4app.py”,第5行,在
文件“ExtensionLoader_PyQt4_QtGui.py”,第22行,在
文件“ExtensionLoader_PyQt4_QtGui.py”,第14行,在引导程序中__
导入错误:dlopen(/Users/thomasdeneux/cx_Freeze-4.3.3/cx_Freeze/samples/PyQt4/build/exe.macosx-10.5-x86_64-2.7/PyQt4.QtGui.so,2):未加载库:@loader_path/../../../libQtGui.4.dylib
引用自:/Users/thomasdeneux/cx_Freeze-4.3.3/cx_Freeze/samples/PyQt4/build/exe.macosx-10.5-x86_64-2.7/PyQt4.QtGui.so
原因:找不到图像
exe.macosx-10.5-x86_64-2.7$
有些Qt库可能找不到,因为它们被完整的相对路径引用,而在发行版中,所有库都被复制到同一文件夹中

然后我转到了Py2App,希望另一个包不会遇到这样的问题。我现在不显示所有细节,只显示尝试构建(这次我不需要修改代码来运行构建)和运行另一个简单的基于Qt的helloworld程序时最重要的行:

test$ py2applet --make-setup helloworld.py
    Wrote setup.py
test$ python setup.py py2app
    running py2app
    creating /Users/thomasdeneux/Documents/spyderworkspace/securebox/python/build/bdist.macosx-10.5-x86_64
    ...
    Done!
test$ ./dist/helloworld.app/Contents/MacOS/helloworld 
    Traceback (most recent call last):
      File "/Users/thomasdeneux/Documents/spyderworkspace/securebox/python/dist/helloworld        .app/Contents/Resources/__boot__.py", line 351, in <module>
        _run()
      File "/Users/thomasdeneux/Documents/spyderworkspace/securebox/python/dist/helloworld        .app/Contents/Resources/__boot__.py", line 336, in _run
        exec(compile(source, path, 'exec'), globals(), globals())
      File "/Users/thomasdeneux/Documents/spyderworkspace/securebox/python/dist/helloworld        .app/Contents/Resources/helloworld.py", line 4, in <module>
        from PyQt4.QtGui import *
      File "PyQt4/QtGui.pyc", line 14, in <module>
      File "PyQt4/QtGui.pyc", line 10, in __load
    ImportError: dlopen(/Users/thomasdeneux/Documents/spyderworkspace/securebox/python/dist/helloworld.app/Contents/Resources/lib/python2.7/lib-dynload/PyQt4/QtGui.so, 2): Library not loaded: @loader_path/../../../libQtGui.4.dylib
      Referenced from: /Users/thomasdeneux/Documents/spyderworkspace/securebox/python/dist/helloworld.app/Contents/Resources/lib/python2.7/lib-dynload/PyQt4/QtGui.so
      Reason: image not found
    2015-05-16 20:40:41.546 helloworld[983:707] helloworld Error
test$ 
test$py2applet——设置helloworld.py
编写setup.py
test$python setup.py py2app
运行py2app
创建/Users/thomasdeneux/Documents/spyderworkspace/securebox/python/build/bdist.macosx-10.5-x86_64
...
完成!
测试$./dist/helloworld.app/Contents/MacOS/helloworld
回溯(最近一次呼叫最后一次):
文件“/Users/thomasdeneux/Documents/spyderworkspace/securebox/python/dist/helloworld.app/Contents/Resources/_boot__.py”,第351行,在
_运行()
文件“/Users/thomasdeneux/Documents/spyderworkspace/securebox/python/dist/helloworld.app/Contents/Resources/\uuuu boot\uuuuuuuuuuuuu.py”,第336行,正在运行
exec(编译(源代码,路径,'exec'),globals(),globals())
文件“/Users/thomasdeneux/Documents/spyderworkspace/securebox/python/dist/helloworld.app/Contents/Resources/helloworld.py”,第4行,在
从PyQt4.QtGui导入*
文件“PyQt4/QtGui.pyc”,第14行,在
加载文件“PyQt4/QtGui.pyc”,第10行
导入错误:dlopen(/Users/thomasdeneux/Documents/spyderworkspace/securebox/python/dist/helloworld.app/Contents/Resources/lib/python2.7/lib-dynload/PyQt4/QtGui.so,2):未加载库:@loader\u path/../../../libQtGui.4.dylib
引用自:/Users/thomasdeneux/Documents/spyderworkspace/securebox/python/dist/helloworld.app/Contents/Resources/lib/python2.7/lib-dynload/PyQt4/QtGui.so
原因:找不到图像
2015-05-16 20:40:41.546 helloworld[983:707]helloworld错误
测试美元
出现了完全相同的问题


感谢所有能够提供帮助的人,无论是直接解决问题,还是建议从python/Qt项目为Mac创建独立程序的另一种策略。

我转而使用py2app和使用自制的python安装。这对我很有用。(我会尝试一下,然后发布结果)