在MacOSX上将cx_freeze与PyQT5和Python 3结合使用 [英] Using cx_freeze with PyQT5 and Python 3 on MacOSX

查看:95
本文介绍了在MacOSX上将cx_freeze与PyQT5和Python 3结合使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在运行10.9.2的MacOS上使用cx_freeze 4.3.3,并在一个非常简单的带有Python 3.3的PyQt5脚本上使用。

I'm trying to use cx_freeze 4.3.3 on a MacOS running 10.9.2 on a very simple PyQt5 script with Python 3.3.

不返回错误,并输出.app。但是,从终端运行.app时,出现错误:

No errors are returned and the .app is output. However when running the .app from terminal I obtain the error:

LSOpenURLsWithRole() failed with error -10810

根据苹果的文档,这是未知错误。

which according to Apple's documentation is "Unknown Error".

我尝试运行的非常简单的代码(PyQt5app.py)是:

The very simple code I try to run (PyQt5app.py) is:

import sys
from PyQt5.QtWidgets import QApplication, QDialog

app = QApplication(sys.argv)
form = QDialog()
form.show()
app.exec_()

文件setup.py为:

The file setup.py is:

import sys
from cx_Freeze import setup, Executable

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

options = {
    'build_exe': {
        'excludes': ['Tkinter']  # Sometimes a little finetuning is needed
    }
}

executables = [
    Executable('PyQt5app.py', base=base)
]

setup(name='PyQt5app',
      version='0.1',
      description='Sample PyQt5 GUI',
      executables=executables,
      options=options
      )

,然后在运行时调用:

sudo python cx_freeze bdist_mac

获取此日志: http:/ /pastebin.com/VBxyyBRn

上面的应用返回错误。

我看到这可能是与在应用程序中包含qt文件有关的问题(或者至少这是PyQt4上的问题),所以我尝试指定qt-menu-nib目录:

So, reading around I see it might be a problem related to including qt files in the app (or at least this was the issue on PyQt4) so I try specifying the qt-menu-nib directory:

sudo python setup.py bdist_mac --qt-menu-nib=/Users/franco/Qt5.2.1/5.2.1/clang_64/plugins/platforms/

获取此日志: http ://pastebin.com/TpRdrSmT

,并且出现同样的无效错误。

and the same not working error.

如果我从PyQt5app.app/Contents/MacOS/PyQt5app运行该应用程序,则会遇到很多引导错误:

If I run the app from PyQt5app.app/Contents/MacOS/PyQt5app I get a lot of bootstrap errors:

Traceback (most recent call last):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/cx_Freeze-4.3.3-py3.3-macosx-10.9-x86_64.egg/cx_Freeze/initscripts/Console.py", line 27, in <module>
    exec(code, m.__dict__)
  File "PyQt5app.py", line 5, in <module>
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py", line 1565, in _find_and_load
    return _find_and_load_unlocked(name, import_)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py", line 1532, in _find_and_load_unlocked
    loader.load_module(name)
  File "ExtensionLoader_PyQt5_QtWidgets.py", line 22, in <module>
  File "ExtensionLoader_PyQt5_QtWidgets.py", line 14, in __bootstrap__
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py", line 1565, in _find_and_load
    return _find_and_load_unlocked(name, import_)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py", line 1532, in _find_and_load_unlocked
    loader.load_module(name)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py", line 584, in _check_name_wrapper
    return method(self, name, *args, **kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py", line 495, in set_package_wrapper
    module = fxn(*args, **kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py", line 508, in set_loader_wrapper
    module = fxn(self, *args, **kwargs)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py", line 1132, in load_module
    fullname, self.path)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py", line 313, in _call_with_frames_removed
    return f(*args, **kwds)
SystemError: initialization of sip raised unreported exception

不用说从终端启动时脚本可以正常工作:

Needless to say the script works fine when launching from terminal:

python PyQt5app.py

我肯定是做错了什么,所以请有人可以帮我吗?

I most certainly am doing something wrong, so please, can anybody help me?

推荐答案

因此,经过长时间的战斗,这里的问题是:libzmq。
我安装了libzmq并指定了--qt-menu-nib选项,上面的简单示例都在这两个目录中运行:

So, after long fighting here is the issue: libzmq . I installed libzmq and specified the --qt-menu-nib option and the simple example above runs in both:

sudo python setup.py build

sudo python setup.py bdist_mac

逐步说明:

我在大多数python33软件包中都使用了mac端口,因此其余部分我都坚持使用。
Libzmq在Macports上不可用,但它的依赖项是。
因此:

I used mac ports for most of my python33 packages so I sticked to it for the rest. Libzmq is not available on macports but its dependencies are. So:

1)安装libtool,autoconf,automake:

1) install libtool, autoconf, automake:

sudo port install libtool
sudo port install autoconf
sudo port install automake

2)从 https://github.com/zeromq/libzmq 中获取libzmq的最新版本。 (我是为了订购而下载ZIP的)并解压缩/导航到文件夹

2) grab the latest version of libzmq from https://github.com/zeromq/libzmq ( I downloaded the ZIP for sake of order ) and unzip/navigate to the folder

/libzmq-master

现在文件夹中INSTALL文档中提供的说明非常清楚,如果您安装了所有依赖项,就可以了。
运行:

now the instructions provided in the INSTALL document in the folder are pretty clear, if you installed all the dependencies then you will be fine. run:

sudo ./autogen.sh
sudo ./configure
sudo make
sudo make install

3)从 https://bitbucket.org/anthony_tuininga/cx_freeze/downloads 然后解压缩/取消导航到文件夹并运行:

3) download the latest cx_freeze from https://bitbucket.org/anthony_tuininga/cx_freeze/downloads then unzip/untar navigate to folder and run:

sudo python setup.py build
sudo python setup.py install

现在为使用Python3.3和PyQt5的MacOSX编译代码时,可以运行:

now when compiling code for MacOSX that uses Python3.3 and PyQt5 you can run:

sudo python setup.py build

然后在build文件夹中导航并运行程序

then navigate in the build folder and run the program as:

./nameoftheprogram

一旦确定了这项工作,然后使用以下命令构建应用或dmg(如您所愿):

once you made sure this work then build the app or dmg (as you prefer) with:

sudo python setup.py bdist_mac --qt-menu-nib=/Users/username/Qt5.2.1/5.2.1/clang_64/plugins/platforms/

其中,路径是Qt5安装的路径。如果我不使用--qt-menu-nib选项,则应用程序将在启动时崩溃,而构建可以正常运行。

where the path is the path to your Qt5 installation. If I don't use the --qt-menu-nib option the app crashes on startup whereas the build works fine.

希望这对以后的工作有所帮助。

Hope this will help someone in the future.

这篇关于在MacOSX上将cx_freeze与PyQT5和Python 3结合使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆