我试图使用PyInstaller来创建一个运行我已经制作的GUI的独立OSX应用程序。当我在终端中输入以下内容时:
pyinstaller gui.py
一切似乎都有效,直到我收到以下错误:
File "/Users/username/anaconda/bin/PyInstaller", line 11, in <module>
sys.exit(run())
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/__main__.py", line 90, in run
run_build(pyi_config, spec_file, **vars(args))
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/__main__.py", line 46, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/build_main.py", line 788, in main
build(specfile, kw.get('distpath'), kw.get('workpath'),
kw.get('clean_build'))
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/build_main.py", line 734, in build
exec(text, spec_namespace)
File "<string>", line 16, in <module>
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/build_main.py", line 212, in __init__
self.__postinit__()
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/datastruct.py", line 178, in __postinit__
self.assemble()
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/build_main.py", line 470, in assemble
module_hook.post_graph()
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/imphook.py", line 409, in post_graph
self._load_hook_module()
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/building/imphook.py", line 376, in
_load_hook_module
self.hook_module_name, self.hook_filename)
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/hooks/hook-PyQt4.py", line 33, in <module>
(qt_menu_nib_dir('PyQt4'), ''),
File "/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/utils/hooks/qt.py", line 125, in qt_menu_nib_dir
""".format(namespace, path))
Exception:
Cannot find qt_menu.nib for PyQt4
Path checked:
/Users/felipe/miniconda/envs/_build/lib/QtGui.framework/Resources/qt_menu.nib
这看起来很奇怪,因为我的名字不是felipe!
我有几个问题:
1)我的电脑上名称felipe下有一个目录怎么可能? (我用anaconda来安装qt,我不知道这是否与它有关?)
2)在我收到错误消息之前,PyInstaller正在查找正确的文件夹。为什么它开始在这个含糊不清(对我来说模糊)的目录中看到我不知道的?
3)我对目录很新手,我无法在计算机的任何地方找到先生felipe。当我查看“用户”文件夹时,我只看到自己的用户和一个空的&#34;共享&#34;夹。 (我不知道共享文件夹的用途以及它的原因。)
4)根据我在互联网上阅读的内容,我将qt_menu-nib复制到了应该变成独立脚本的文件夹中。为了从这里成功创建独立,我该怎么办?
答案 0 :(得分:4)
首先,你面对PyInstaller和Anaconda之间的一个已知问题:PyInstaller issue #2135。对话包含您问题的答案。
1)路径是由Anaconda提供的错误构建的Qt二进制文件中的硬编码,请参阅comment from mrady3。
2)PyInstaller加载Qt4-specific hook以查找运行目标应用程序所需的资源(qt_menu.nib
)。钩子代码试图从Qt二进制文件本身获取资源目录的位置。 Qt二进制文件返回错误/硬编码/路径,然后该过程失败。
3)参见第1点),它是维护者机器上的一个文件夹。 Qt假设它的安装路径是在建造之前预先设定的; Anaconda存储库托管的二进制文件在编译时考虑了另一个安装路径。
4)可能有几种可能的方法:
尝试从源代码安装PyInstaller的开发人员版本,它有some fixes for the above-mentioned issue。然后再次尝试构建应用程序:
git clone https://github.com/pyinstaller/pyinstaller.git
cd pyinstaller
/Users/username/anaconda/bin/python setup.py sdist
conda install dist/PyInstaller-3.3.dev0.tar.bz2
使用homebrew安装Qt4。本地编译需要很长时间:
brew install cartr/qt4/qt
find /usr/local/Cellar/qt -name qt_menu.nib
在/Users/username/anaconda/lib/python2.7/site-
packages/PyInstaller/hooks/hook-PyQt4.py
修改Qt4挂钩,并将来自自制安装(qt_menu_nib_dir('PyQt4')
)的路径替换为'/usr/local/Cellar/qt/4.8.7_3/lib/QtGui.framework/Versions/4/Resources/qt_menu.nib'
。
或者,只需将qt_menu.nib
放入预期的位置:
sudo mkdir -p /Users/felipe/miniconda/envs/_build/lib/QtGui.framework/Resources/
sudo ln -s /usr/local/Cellar/qt/4.8.7_3/lib/QtGui.framework/Versions/4/Resources/qt_menu.nib /Users/felipe/miniconda/envs/_build/lib/QtGui.framework/Resources/