异常:使用Pyinstaller时无法找到PyQt5插件目录,尽管根本没有使用PyQt5。

18
一个月前,我解决了我的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`

这篇文章可能与此有关?不过我正在使用Pyinstaller,没有setup.py文件,所以不知道如何利用那里的解决方案。

我觉得这个错误信息很奇怪,因为我并没有使用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

我想说,我也不知道如何理解TypeError: a bytes-like object is required, not 'str'这里可能有关系吗?就我所知,我只在少数情况下使用pickle的二进制模式,而且这是我的唯一用法:

pickle.dump( roiState, open( fileName, "wb" ) )
roiState = pickle.load(open(fileName, "rb"))

我运行应用程序时没有任何错误,但尝试使用pyinstaller生成.exe文件时出现了这些错误。为什么?请注意,Anaconda3在上面的回溯中也弹出了(为什么它要在那里寻找二进制文件?),但是我已经:

  1. 从Anaconda中卸载了pyinstaller
  2. 正在使用标准的Python 3.5(64位)编译器

我能想到的唯一可能是罪魁祸首的是,我不再使用Pyinstaller的开发版本(它无法在Python 3.5中运行)。 我必须使用开发版本来解决我的冻结问题,这里当我的代码是针对Python 2.7编写时。

7个回答

17

我成功地解决了遇到的相同问题(conda 4.5.4,pyinstaller 3.4),而无需卸载conda:

pip install PyQt5

当我使用conda install jupyter seaborn时,conda已经安装了PyQt。有趣的是,使用conda install PyQt5并不能解决我的问题。我不知道为什么。无论如何,我希望这可以帮助到某个人。


据我所知,conda的问题是这样的。如果它在当前环境下不可用,它会查找基础环境。因此,如果我们使用pip安装它,那么它将确保使用正确的环境。 - Ajeeb.K.P
在conda 4.6.14和已安装pyqt 5.9.2的情况下,我无法通过pip install PyQt5安装PyQt5,这会导致兼容性错误。参考我对类似问题的回答,安装最新版本的PyInstaller对我有用。 - Zhenyu

5

对于我而言,这篇文章中的所有答案都没有解决我的问题,但是我在几个月前的这个帖子中找到了一个解决方案,并且它起作用了。如果其他人遇到类似的问题,并在看到这篇文章之前先看到另一篇文章,请在此处添加链接。

解决方案是在 pyinstaller 语句后面添加 --exclude-module PyQt5


4
我认为当前版本的pyinstaller存在问题。我卸载了默认版:

pip uninstall pyinstaller

然后安装了最新的试用版:

pip install https://github.com/pyinstaller/pyinstaller/archive/develop.zip

之后它就可以正常工作了。
更多信息请参见:https://github.com/pyinstaller/pyinstaller/issues/3938

2

[针对 Anaconda 安装] 我遇到了相同的问题,但当我更新 Anaconda 后问题得到了解决。从 Anaconda 命令提示符运行以下命令进行更新:conda update anaconda。这将更新多个包,包括 pyqt。


1

在尝试将名为main.py的脚本转换为.exe时,对我有帮助的是kierabeth的变体。更具体地说,如下所示:

  1. first create a spec file and exclude the PyQt5 module

    pyi-makespec --onefile main.py --exclude-module PyQt5
    
  2. then build the spec file

    pyinstaller main.spec
    

1

卸载Anaconda后一切正常...我得出结论,如果您使用Pyinstaller,则不能同时安装Anaconda和使用标准的Python 3.5编译器。也许this有关。

这不是第first次卸载Anaconda似乎解决了我的问题...如果我应该在哪里报告此问题,请在下面评论。我不知道在哪里。


据我所知,conda的问题是这样的。如果它在当前环境中不可用,它会查找基础环境。 - Ajeeb.K.P

1
这似乎仍然是一个问题,这就是为什么我会重新发表这篇旧帖子的原因,以防像我一样的人搜索解决方案。

你不需要卸载或重新安装任何东西。我只是安装了最新版本的Anaconda和pyinstaller,并再次遇到了相同的错误。

问题出在../Anaconda3\Lib\site-packages\PyInstaller\utils\hooks\qt.py文件上。

解决方案在以下链接中。 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

我希望PyInstaller开发人员能在某个阶段修复这个问题。


请在您的答案中引用链接页面的相关部分。 - Aimery

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接