Python 例外:即使没有使用 PyQt5,在使用 Pyinstaller 时也找不到 PyQt5 插件目录
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39736000/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Exception: Cannot find PyQt5 plugin directories when using Pyinstaller despite PyQt5 not even being used
提问by Frikster
A month ago I solved my applcation freezing issues for Python 2.7 as you can see here. I have since adapted my code to python 3.5 (using Anaconda) and it appears to be working. couldn't get pyinstaller working with Anaconda so switched to trying to generate an .exe using the standard Python 3.5 compiler. I am using the same settings as in the link above (pyinstaller --additional-hooks-dir=. --clean --win-private-assemblies pipegui.py
), except I get the following error message instead:
一个月前,我解决我的applcation冻结问题为Python 2.7,你可以看到在这里。我已经将我的代码调整为 python 3.5(使用 Anaconda)并且它似乎正在工作。无法让 pyinstaller 与 Anaconda 一起工作,因此切换到尝试使用标准 Python 3.5 编译器生成 .exe。我使用的设置与上面链接 ( pyinstaller --additional-hooks-dir=. --clean --win-private-assemblies pipegui.py
)中的设置相同,但我收到以下错误消息:
`Exception: Cannot find PyQt5 plugin directories`
Thismay be related? Except I'm using Pyinstaller and I don't have a setup.py so don't know how I can make use of the solution there, if at all
这可能有关系?除了我正在使用 Pyinstaller 并且我没有 setup.py 所以我不知道如何使用那里的解决方案,如果有的话
I find this error message bizarre because I am not using PyQt5, but PyQt4. Here is the full output:
我觉得这个错误消息很奇怪,因为我没有使用 PyQt5,而是 PyQt4。这是完整的输出:
C:\Users\Cornelis Dirk Haupt\PycharmProjects\Mesoscale-Brain-Explorer\src>pyinstaller --additional-hooks-dir=. --clean --win-private-assemblies pipegui.py
62 INFO: PyInstaller: 3.2
62 INFO: Python: 3.5.0
62 INFO: Platform: Windows-10.0.14393
62 INFO: wrote C:\Users\Cornelis Dirk Haupt\PycharmProjects\Mesoscale-Brain-Explorer\src\pipegui.spec
62 INFO: UPX is not available.
62 INFO: Removing temporary files and cleaning cache in C:\Users\Cornelis Dirk Haupt\AppData\Roaming\pyinstaller
62 INFO: Extending PYTHONPATH with paths
['C:\Users\Cornelis Dirk Haupt\PycharmProjects\Mesoscale-Brain-Explorer',
'C:\Users\Cornelis Dirk '
'Haupt\PycharmProjects\Mesoscale-Brain-Explorer\src']
62 INFO: checking Analysis
62 INFO: Building Analysis because out00-Analysis.toc is non existent
62 INFO: Initializing module dependency graph...
62 INFO: Initializing module graph hooks...
62 INFO: Analyzing base_library.zip ...
1430 INFO: running Analysis out00-Analysis.toc
1727 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-math-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 695, in getImports
return _getImports_pe(pth)
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 122, in _getImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
1742 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-runtime-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 695, in getImports
return _getImports_pe(pth)
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 122, in _getImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
1742 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-locale-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 695, in getImports
return _getImports_pe(pth)
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 122, in _getImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
1758 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-stdio-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 695, in getImports
return _getImports_pe(pth)
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 122, in _getImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
1758 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-heap-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 695, in getImports
return _getImports_pe(pth)
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 122, in _getImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
1774 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-string-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 695, in getImports
return _getImports_pe(pth)
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 122, in _getImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
1774 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-environment-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 695, in getImports
return _getImports_pe(pth)
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 122, in _getImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
1774 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-time-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 695, in getImports
return _getImports_pe(pth)
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 122, in _getImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
1789 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-filesystem-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 695, in getImports
return _getImports_pe(pth)
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 122, in _getImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
1789 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-conio-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 695, in getImports
return _getImports_pe(pth)
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 122, in _getImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
1789 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-process-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 695, in getImports
return _getImports_pe(pth)
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 122, in _getImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
1805 WARNING: Can not get binary dependencies for file: C:\Anaconda3\api-ms-win-crt-convert-l1-1-0.dll
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 695, in getImports
return _getImports_pe(pth)
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\depend\bindepend.py", line 122, in _getImports_pe
dll, _ = sym.forwarder.split('.')
TypeError: a bytes-like object is required, not 'str'
1805 INFO: Caching module hooks...
1805 INFO: Analyzing C:\Users\Cornelis Dirk Haupt\PycharmProjects\Mesoscale-Brain-Explorer\src\pipegui.py
1992 INFO: Processing pre-find module path hook distutils
2055 INFO: Processing pre-safe import module hook six.moves
3181 INFO: Processing pre-find module path hook site
3181 INFO: site: retargeting to fake-dir 'c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\fake-modules'
4298 INFO: Processing pre-safe import module hook win32com
9975 INFO: Loading module hooks...
9975 INFO: Loading module hook "hook-_tkinter.py"...
10121 INFO: checking Tree
10121 INFO: Building Tree because out00-Tree.toc is non existent
10122 INFO: Building Tree out00-Tree.toc
10184 INFO: checking Tree
10184 INFO: Building Tree because out01-Tree.toc is non existent
10185 INFO: Building Tree out01-Tree.toc
10198 INFO: Loading module hook "hook-matplotlib.py"...
10404 INFO: Loading module hook "hook-pywintypes.py"...
10526 INFO: Loading module hook "hook-xml.py"...
10526 INFO: Loading module hook "hook-pydoc.py"...
10527 INFO: Loading module hook "hook-scipy.linalg.py"...
10527 INFO: Loading module hook "hook-scipy.sparse.csgraph.py"...
10529 INFO: Loading module hook "hook-plugins.py"...
10721 INFO: Processing pre-find module path hook PyQt4.uic.port_v3
10726 INFO: Processing pre-find module path hook PyQt4.uic.port_v2
12402 INFO: Loading module hook "hook-OpenGL.py"...
12583 INFO: Loading module hook "hook-PyQt4.QtGui.py"...
12802 INFO: Loading module hook "hook-encodings.py"...
12807 INFO: Loading module hook "hook-PyQt4.uic.py"...
12812 INFO: Loading module hook "hook-PyQt5.QtWidgets.py"...
12813 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
12813 INFO: Loading module hook "hook-setuptools.py"...
12814 INFO: Loading module hook "hook-scipy.special._ufuncs.py"...
12814 INFO: Loading module hook "hook-PyQt5.QtCore.py"...
Traceback (most recent call last):
File "<string>", line 2, in <module>
ImportError: DLL load failed: The specified procedure could not be found.
Traceback (most recent call last):
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\runpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:\Users\Cornelis Dirk Haupt\AppData\Local\Programs\Python\Python35\Scripts\pyinstaller.exe\__main__.py", line 9, in <module>
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\__main__.py", line 90, in run
run_build(pyi_config, spec_file, **vars(args))
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\__main__.py", line 46, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\building\build_main.py", line 788, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\building\build_main.py", line 734, in build
exec(text, spec_namespace)
File "<string>", line 16, in <module>
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\building\build_main.py", line 212, in __init__
self.__postinit__()
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\building\datastruct.py", line 178, in __postinit__
self.assemble()
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\building\build_main.py", line 470, in assemble
module_hook.post_graph()
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\building\imphook.py", line 409, in post_graph
self._load_hook_module()
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\building\imphook.py", line 376, in _load_hook_module
self.hook_module_name, self.hook_filename)
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\compat.py", line 725, in importlib_load_source
return mod_loader.load_module()
File "<frozen importlib._bootstrap_external>", line 385, in _check_name_wrapper
File "<frozen importlib._bootstrap_external>", line 806, in load_module
File "<frozen importlib._bootstrap_external>", line 665, in load_module
File "<frozen importlib._bootstrap>", line 268, in _load_module_shim
File "<frozen importlib._bootstrap>", line 693, in _load
File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 662, in exec_module
File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\hooks\hook-PyQt5.QtCore.py", line 15, in <module>
binaries = qt_plugins_binaries('codecs', namespace='PyQt5')
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 64, in qt_plugins_binaries
pdir = qt_plugins_dir(namespace=namespace)
File "c:\users\cornelis dirk haupt\appdata\local\programs\python\python35\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 38, in qt_plugins_dir
raise Exception('Cannot find {0} plugin directories'.format(namespace))
Exception: Cannot find PyQt5 plugin directories
I will say I also have no clue what to make of the TypeError: a bytes-like object is required, not 'str'
Thismay be related? I only use binary mode with pickle a handful of times as far as I can tell this is my only usage:
我会说我也不知道该怎么做TypeError: a bytes-like object is required, not 'str'
这可能与此有关?据我所知,我只使用带有 pickle 的二进制模式几次,这是我唯一的用法:
pickle.dump( roiState, open( fileName, "wb" ) )
roiState = pickle.load(open(fileName, "rb"))
I don't have any errors when I run the application, only getting these errors when trying to generate an .exe using pyinstaller. Why?
我在运行应用程序时没有任何错误,只有在尝试使用 pyinstaller 生成 .exe 时才会出现这些错误。为什么?
Note also that Anaconda3 does pop up in the traceback above (why is it looking for binaries there?) but I:
还要注意 Anaconda3 确实会在上面的回溯中弹出(为什么它在那里寻找二进制文件?)但我:
- Uninstalled pyinstaller from Anaconda
- Am using the standard Python 3.5 (64-bit) compiler
- 从 Anaconda 卸载 pyinstaller
- 正在使用标准的 Python 3.5(64 位)编译器
Only thing I can think of that may be the culprit is that I'm no longer using the developer version of Pyinstaller (it just flat does not run in Python 3.5). I had to use the developer version to solve my freezing issue herewhen my code was written for python 2.7
我唯一能想到的可能是罪魁祸首是我不再使用 Pyinstaller 的开发人员版本(它只是不能在 Python 3.5 中运行)。我原来用的是开发者版本,以解决我的问题,冻结这里时,我的代码是为Python 2.7编写
采纳答案by Frikster
Uninstall Anaconda and everything works... I conclude that you simply cannot have Anaconda installed and use the standard Python 3.5 compiler at the same time if you're using Pyinstaller. Maybe thisis related.
卸载 Anaconda,一切正常……我的结论是,如果您使用 Pyinstaller,您根本无法安装 Anaconda 并同时使用标准的 Python 3.5 编译器。也许这是相关的。
This is not the firsttime that uninstalling Anaconda appears to solve my issues... If I should report this issue somewhere please comment below. I don't know where.
这不是第一次卸载 Anaconda 似乎可以解决我的问题......如果我应该在某处报告这个问题,请在下面发表评论。我不知道在哪里。
回答by mikey
I managed to fix the same problem I encountered (conda 4.5.4, pyinstaller 3.4) without uninstalling conda:
我设法解决了我遇到的相同问题(conda 4.5.4,pyinstaller 3.4)而没有卸载 conda:
pip install PyQt5
conda already installed PyQt when I used conda install jupyter seaborn
. Interestingly, using conda install PyQt5
does not fix my problem. I don't know why. In any case I hope this may help someone out there.
当我使用 .conda 时,conda 已经安装了 PyQt conda install jupyter seaborn
。有趣的是,使用conda install PyQt5
并不能解决我的问题。我不知道为什么。无论如何,我希望这可以帮助那里的人。
回答by NAP_time
I think there is an issue with the current version of pyinstaller. I uninstalled the default version.
我认为当前版本的 pyinstaller 存在问题。我卸载了默认版本。
pip uninstall pyinstaller
pip uninstall pyinstaller
and installed the latest trial version
并安装了最新的试用版
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip
and then it worked for me.
然后它对我有用。
More information here: https://github.com/pyinstaller/pyinstaller/issues/3938
更多信息在这里:https: //github.com/pyinstaller/pyinstaller/issues/3938
回答by kierabeth
None of the answers on this post worked for me, but I found this threadfrom a few months ago and it worked. Linking it here in case others run into a similar problem and come across this thread before the other one.
这篇文章中的所有答案都不适合我,但我在几个月前找到了这个线程,并且它起作用了。将它链接到这里以防其他人遇到类似的问题并在另一个线程之前遇到这个线程。
The solution is to add --exclude-module PyQt5
after the pyinstaller statement.
解决办法是--exclude-module PyQt5
在pyinstaller语句后添加。
回答by KGS
[specifically for an anacodna installation] I had the same problem, but it got fixed when I updated anaconda.
From the Anaconda prompt: conda update anaconda
. This updates several packages including pyqt
[专门针对 anaconda 安装] 我遇到了同样的问题,但是当我更新 anaconda 时它得到了修复。从 Anaconda 提示符:conda update anaconda
. 这更新了几个包,包括 pyqt
回答by NMech
What worked for me (whicle trying to convert to .exe a script named main.py) is a variation of kierabeth. More specifically the following:
什么工作对我来说(whicle试图转换到.EXE名为脚本main.py)是变化kierabeth。更具体的如下:
first create a spec file and exclude the PyQt5 module
pyi-makespec --onefile main.py --exclude-module PyQt5
then build the spec file
pyinstaller main.spec
首先创建一个spec文件并排除PyQt5模块
pyi-makespec --onefile main.py --exclude-module PyQt5
然后构建规范文件
pyinstaller main.spec
回答by INsanE Alchemist
This still looks like an issue, which is why I'm resurrecting this old post in the event someone like me googles for a fix to the same issue.
这看起来仍然是一个问题,这就是为什么我会在像我这样的人用谷歌搜索相同问题的情况下重新发布这篇旧帖子的原因。
You don't need to uninstall or reinstall anything. I just installed latest version of Anaconda and pyinstaller and have come across the same error again.
您不需要卸载或重新安装任何东西。我刚刚安装了最新版本的 Anaconda 和 pyinstaller,又遇到了同样的错误。
The problem is the ../Anaconda3\Lib\site-packages\PyInstaller\utils\hooks\qt.py file.
问题是 ../Anaconda3\Lib\site-packages\PyInstaller\utils\hooks\qt.py 文件。
The solution lies in the following link. https://github.com/pyinstaller/pyinstaller/issues/3938
解决方案在以下链接中。 https://github.com/pyinstaller/pyinstaller/issues/3938
json_str = exec_statement("""
# ... some code here ...
else:
# QLibraryInfo isn't always valid until a QCoreApplication is
# instantiated.
app = QCoreApplication(sys.argv) # this is the part that's needed
I hope the pyinstaller devs fix this at some stage.
我希望 pyinstaller 开发人员在某个阶段解决这个问题。