此应用程序无法启动,因为它无法找到或加载Qt平台插件"cocoa"

 相思和怀恋_811_372 发布于 2022-12-29 12:33

我想我在过去的20个小时内尽我所能,但似乎没有任何效果.我的应用程序正在运行和工作 - 就像它应该 - 我唯一的问题是我无法.app从它创建一个包.我都尝试Py2Appcx_Freeze,但他们的非正常工作.由于多平台支持,我会坚持使用后者 - 如果可能的话.

setup.py如下所示:

import sys
from cx_Freeze import setup, Executable

base = None
if sys.platform == 'win32':
    base = 'Win32GUI'

OPTIONS = {'build_exe': {'includes': ['sip',
                                      'PyQt5',
                                      'PyQt5.QtCore',
                                      'PyQt5.QtGui',
                                      'PyQt5.QtWidgets',
                                      'PyQt5.QtMultimediaWidgets',
                                      'PyQt5.QtMultimedia',
                                      'PyQt5.QtNetwork']}}

EXECUTABLES = [Executable('main.py', base=base)]
NAME = 'coublet'
VERSION = '0.5.70'

setup(name = NAME,
      version = VERSION,
      options = OPTIONS,
      executables = EXECUTABLES)

我有的错误信息是这样的:

objc[28404]: Class NotificationReceiver is implemented in both
/Users/.../build/coublet-0.5.70.app/Contents/MacOS/QtWidgets and
/usr/local/Cellar/qt5/5.3.1/lib/QtWidgets.framework/Versions/5/QtWidgets. One of
the two will be used. Which one is undefined.
QObject::moveToThread: Current thread (0x7fc4b96e98b0) is not the object's thread
(0x7fc4b95dbc80).
Cannot move to target thread (0x7fc4b96e98b0)

On Mac OS X, you might be loading two sets of Qt binaries into the same process.
Check that all plugins are compiled against the right Qt binaries. Export
DYLD_PRINT_LIBRARIES=1 and check that only one set of binaries are being loaded.
This application failed to start because it could not find or load the Qt
platform plugin "cocoa".

Available platform plugins are: cocoa, minimal, offscreen.

Reinstalling the application may fix this problem.
Abort trap: 6

我的系统信息:

Mac OS X  : 10.9.4
Python    :  3.4.1
cx_Freeze :  0.9
PyQt5:    :  5.3.1
- - -
Packages installed via: Homebrew and PIP

.app 结构体:

build/coublet-0.5.70.app
??? Contents
    ??? Frameworks
    ??? Info.plist
    ??? MacOS
    ?   ??? PyQt5.QtCore.so
    ?   ??? PyQt5.QtGui.so
    ?   ??? PyQt5.QtMultimedia.so
    ?   ??? PyQt5.QtMultimediaWidgets.so
    ?   ??? PyQt5.QtNetwork.so
    ?   ??? PyQt5.QtWidgets.so
    ?   ??? Python
    ?   ??? QtCore
    ?   ??? QtCore.so
    ?   ??? QtGui
    ?   ??? QtGui.so
    ?   ??? QtMultimedia
    ?   ??? QtMultimedia.so
    ?   ??? QtMultimediaWidgets
    ?   ??? QtMultimediaWidgets.so
    ?   ??? QtNetwork
    ?   ??? QtNetwork.so
    ?   ??? QtOpenGL
    ?   ??? QtWidgets
    ?   ??? QtWidgets.so
    ?   ??? _bisect.so
    ?   ??? _bz2.so
    ?   ??? _codecs_cn.so
    ?   ??? _codecs_hk.so
    ?   ??? _codecs_iso2022.so
    ?   ??? _codecs_jp.so
    ?   ??? _codecs_kr.so
    ?   ??? _codecs_tw.so
    ?   ??? _datetime.so
    ?   ??? _hashlib.so
    ?   ??? _heapq.so
    ?   ??? _json.so
    ?   ??? _lzma.so
    ?   ??? _md5.so
    ?   ??? _multibytecodec.so
    ?   ??? _opcode.so
    ?   ??? _pickle.so
    ?   ??? _posixsubprocess.so
    ?   ??? _random.so
    ?   ??? _scproxy.so
    ?   ??? _sha1.so
    ?   ??? _sha256.so
    ?   ??? _sha512.so
    ?   ??? _socket.so
    ?   ??? _ssl.so
    ?   ??? _struct.so
    ?   ??? array.so
    ?   ??? binascii.so
    ?   ??? grp.so
    ?   ??? imageformats
    ?   ?   ??? libqdds.dylib
    ?   ?   ??? libqgif.dylib
    ?   ?   ??? libqicns.dylib
    ?   ?   ??? libqico.dylib
    ?   ?   ??? libqjp2.dylib
    ?   ?   ??? libqjpeg.dylib
    ?   ?   ??? libqmng.dylib
    ?   ?   ??? libqsvg.dylib
    ?   ?   ??? libqtga.dylib
    ?   ?   ??? libqtiff.dylib
    ?   ?   ??? libqwbmp.dylib
    ?   ?   ??? libqwebp.dylib
    ?   ??? libcrypto.1.0.0.dylib
    ?   ??? liblzma.5.dylib
    ?   ??? library.zip
    ?   ??? libreadline.6.dylib
    ?   ??? libssl.1.0.0.dylib
    ?   ??? main
    ?   ??? math.so
    ?   ??? platforms
    ?   ?   ??? libqcocoa.dylib
    ?   ?   ??? libqminimal.dylib
    ?   ?   ??? libqoffscreen.dylib
    ?   ??? pyexpat.so
    ?   ??? readline.so
    ?   ??? select.so
    ?   ??? sip.so
    ?   ??? termios.so
    ?   ??? time.so
    ?   ??? unicodedata.so
    ?   ??? zlib.so
    ??? Resources

问题是我觉得很明显:我做错了什么?(或者我不做什么?)

1 个回答
  • cx_Freeze在MacOSX上构建应用程序时,所有依赖库(.soMacOSX上的文件)都打包到应用程序包中.正是这使得应用程序可以移植到其他系统,而无需再次安装Qt.

    因此,在启动应用程序时,应从包中加载库.但是,在您的情况下,系统库仍在加载:

    /Users/.../build/coublet-0.5.70.app/Contents/MacOS/QtWidgets
    /usr/local/Cellar/qt5/5.3.1/lib/QtWidgets.framework/Versions/5/QtWidgets
    

    结果One of the two will be used. Which one is undefined.意味着可以加载其中任何一个.如果它选择了正确的那个,太好了!如果没有,你可以同时加载两组独立的库,之后不久就会失败.顺便说一句,你可能会发现如果你在另一个系统上试用你的应用程序它会工作正常!有时候.

    有关该问题的概述,我建议您查看以下错误#33.

    在你开始之前

    确保安装了最新版本的cx_Freeze.我建议尝试克隆存储库并从那里安装.

    其次,确保Qt插件正确构建到您的应用程序中.Cx_Freeze先前查找了该qt-menu.nib文件以确定它是否正在构建Qt应用程序.这在Qt5中不再可用,但您可以在构建应用程序时在命令行上传递它.将它设置为你想要的任何东西,它无所谓:

    python setup.py bdist_mac --qt-menu-nib=/usr/local/Cellar/qt5/5.3.1/plugins/platforms/
    

    这可能足以解决您的问题.但如果没有,您有两种选择:

    选项1

    每个库文件都包含其依赖项的路径.如果您收到此错误,则表示其中一些路径是a)仍然指向原始文件,或b)不够具体(并且在您的PATH或上找到DYLD_LIBRARY_PATH).但是,您可以重新编写使用路径install_name_tool在命令行(如描述在这里:

    install_name_tool -change /usr/local/Cellar/qt5/5.3.1/lib/QtWidgets.framework/Versions/5/QtWidgets @executable_path/QtWidgets build/MyApp.app/Contents/MacOS/qt_plugins/platforms/libqcocoa.dylib
    install_name_tool -change /usr/local/Cellar/qt5/5.3.1/lib/QtCore.framework/Versions/5/QtCore @executable_path/QtCore build/MyApp.app/Contents/MacOS/qt_plugins/platforms/libqcocoa.dylib
    install_name_tool -change /usr/local/Cellar/qt5/5.3.1/lib/QtPrintSupport.framework/Versions/5/QtPrintSupport @executable_path/QtPrintSupport build/MyApp.app/Contents/MacOS/qt_plugins/platforms/libqcocoa.dylib
    install_name_tool -change /usr/local/Cellar/qt5/5.3.1/lib/QtGui.framework/Versions/5/QtGui @executable_path/QtGui build/MyApp.app/Contents/MacOS/qt_plugins/platforms/libqcocoa.dylib
    

    这将重写库中的路径以指向您的应用程序文件夹,使用@executable_path作为基础.您将需要对发现加载不正确的所有路径执行此操作.我建议把它包装成一个脚本,在构建后自动运行.

    如果要查看文件引用的库,可以使用otool.例如,在我成功构建的应用程序中:

    otool -L libqcocoa.dylib 
    libqcocoa.dylib:
        @executable_path/../Resources/qt_plugins/platforms/libqcocoa.dylib (compatibility version 0.0.0, current version 0.0.0)
        /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 20.0.0) 
    ...
    

    问题跟踪器中有一个更新的解决方法,它表明只需在应用程序中导入正确的模块即可使其正常运行,但是您似乎不可能没有应用程序QtWidgets.

    选项2

    如果上述方法不起作用,则此处列出了另一种方法.这是一个大锤的方法,它只是简单地防止加载插件.

    qt.conf在可执行文件旁边添加一个文件(在.app包含以下内容的包中:
    [Paths] Plugins = '.'

    设置环境变量QT_PLUGIN_PATH=""(您可以在导入之前在应用程序中执行此操作PyQt.或者QtGui.QApplication.setLibraryPaths([])在创建应用程序对象之前调用.

    结果是没有插件,因此您的应用程序将无法访问MacOSX Cocoa样式和UI(例如文件,颜色对话框).

    2022-12-29 12:35 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有