过去的一天基本上是连续不断的挫折。我正在尝试创建我的第一个 pyQt5 应用程序并将其卡住到 OSX 应用程序。这是我迄今为止所做努力的简短时间表:
- 注意到 PyQt5 安装仅适用于 Python3。通过 Homebrew 安装了 Python3 和 pyQt。
- 开发的应用程序。从 PyCharm 启动时一切正常。
- 由于 Pycharm 的 pip 安装程序在任务中失败,因此将 cx_freeze 从源代码安装到 Python3。
- 尝试使用 cx_freeze 卡住应用程序只是为了得到语法错误。通过将以下建议应用于 pyQt5 来解决它:SyntaxError when using cx_freeze on PyQt app
检查了 cx_freeze 的教程:http://www.pythonschool.net/cxfreeze_mac/并通过示例创建了一个 setup.py:
application_title = "simple_PyQt4" #what you want to application to be called main_python_file = "main.py" #the name of the python file you use to run the program import sys from cx_Freeze import setup, Executable base = None if sys.platform == "win32": base = "Win32GUI" includes = ["atexit","re"] setup( name = application_title, version = "0.1", description = "Sample cx_Freeze PyQt4 script", options = {"build_exe" : {"includes" : includes }}, executables = [Executable(main_python_file, base = base)])
使用“bdist_mac”参数运行 cx_freeze。这次生成了 .app 文件。但是,它不会启动。在任何地方都看不到任何错误或信息。单击时根本不会启动。
在这一点上,我真的厌倦了所有这些,所以请帮忙。如果可以,请帮助我: 1.用Homebrew安装PyQt5到Python2.7(试过,没弄明白),这样我就可以使用兼容Python2的打包工具了。 2. 使冷冻过程正常进行。如果可能,请给出详细的解释,我是这些工具的新手。
我也很想听听人们应该如何使用 pyQt5 部署独立应用程序,因为这个过程看起来并不简单。
编辑:我按照 ThomasK 的建议在文件夹中运行结果“main”。我收到以下错误,但不知道这意味着什么:
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.3.4/Frameworks/Python.framework/Versions/3.3/lib/python3.3/site-packages/cx_Freeze-4.3.2-py3.3-macosx-10.9-x86_64.egg/cx_Freeze/initscripts/Console3.py", line 27, in <module>
exec(code, m.__dict__)
File "main.py", line 8, in <module>
File "/usr/local/Cellar/python3/3.3.4/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 "/usr/local/Cellar/python3/3.3.4/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py", line 1512, in _find_and_load_unlocked
_call_with_frames_removed(import_, parent)
File "/usr/local/Cellar/python3/3.3.4/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py", line 313, in _call_with_frames_removed
return f(*args, **kwds)
File "/usr/local/Cellar/python3/3.3.4/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 "/usr/local/Cellar/python3/3.3.4/Frameworks/Python.framework/Versions/3.3/lib/python3.3/importlib/_bootstrap.py", line 1529, in _find_and_load_unlocked
raise exc
ImportError: No module named 'ui'
在 main.py 上,我在第 8 行导入了这个:
from ui.main import Ui_MainWindow
我的项目目录中名为“ui”的文件夹中有所有 .ui 文件及其对应的 .py 文件。
编辑:卡住过程的输出:http://pastebin.com/RR9pNGfR 编辑:我的项目架构:http://pastebin.com/HmsdNXEb
最佳答案
我不知道原始发帖者在解决他们的问题方面走了多远,引用的 pastebins 早就被删除了,所以没有很多补充 Material ,但是 the latest version of those cx_freeze
instructions at pythonschool ,更新于 2014-08-27(在这个问题之后),说:
Unfortunately the current version of cx_Freeze on Mac OS X does not play particularly nicely with Python versions that have been installed from Python.org or PyQt if you have installed it previously using our instructions. Therefore, to ensure that cx_Freeze installs successfully you will need to install Python and PyQt using a package manager called MacPorts.
所以,这可能一直是问题所在。 “通过 Homebrew”安装 Python3 和 PyQt 听起来可能也导致了配置问题。
关于Python 3 + pyQt5 + cx_freeze,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22148930/