将py文件转换为exe,找不到现有的PyQt5插件目录

时间:2018-09-17 22:07:54

标签: python anaconda pyqt5 pyinstaller

我对phyton非常陌生,我刚刚完成了我的第一个应用程序。 现在,我正在尝试将.py文件编译为似乎无法正常工作的.exe购买。 我到处都在寻找解决方案,但我似乎找不到。

当我运行此命令时:pyinstaller gui.py

出现此错误:

4815 INFO: Loading module hooks...
4815 INFO: Loading module hook "hook-encodings.py"...
4913 INFO: Loading module hook "hook-pydoc.py"...
4913 INFO: Loading module hook "hook-PyQt5.py"...
5019 WARNING: Hidden import "PyQt5.sip" not found!
5019 INFO: Loading module hook "hook-PyQt5.QtCore.py"...
5096 WARNING: Unable to find Qt5 translations C:/qt5b/qt_1524647842210/_h_env/Library/translations\qtbase_*.qm. These translations were not packaged.
5096 INFO: Loading module hook "hook-PyQt5.QtGui.py"...
Traceback (most recent call last):
  File "c:\users\ivo\anaconda3\lib\runpy.py", line 193, in _run_module_as_main
    "__main__", mod_spec)
  File "c:\users\ivo\anaconda3\lib\runpy.py", line 85, in _run_code
    exec(code, run_globals)
  File "C:\Users\Ivo\Anaconda3\Scripts\pyinstaller.exe\__main__.py", line 9, in <module>
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 111, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\__main__.py", line 63, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 838, in main
    build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 784, in build
    exec(text, spec_namespace)
  File "<string>", line 17, in <module>
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 241, in __init__
    self.__postinit__()
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\building\datastruct.py", line 158, in __postinit__
    self.assemble()
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\building\build_main.py", line 500, in assemble
    module_hook.post_graph()
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\building\imphook.py", line 410, in post_graph
    self._load_hook_module()
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\building\imphook.py", line 377, in _load_hook_module
    self.hook_module_name, self.hook_filename)
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\compat.py", line 736, in importlib_load_source
    return mod_loader.load_module()
  File "<frozen importlib._bootstrap_external>", line 399, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 823, in load_module
  File "<frozen importlib._bootstrap_external>", line 682, in load_module
  File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 684, in _load
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\hooks\hook-PyQt5.QtGui.py", line 11, in <module>
    hiddenimports, binaries, datas = add_qt5_dependencies(__file__)
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 514, in add_qt5_dependencies
    more_binaries = qt_plugins_binaries(plugin, namespace=namespace)
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 132, in qt_plugins_binaries
    pdir = qt_plugins_dir(namespace=namespace)
  File "c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\utils\hooks\qt.py", line 117, in qt_plugins_dir
    """.format(namespace, ", ".join(paths)))
Exception:
            Cannot find existing PyQt5 plugin directories
            Paths checked: C:/qt5b/qt_1524647842210/_h_env/Library/plugins

我的路径变量:

C:\Users\Ivo\Anaconda3;C:\Users\Ivo\Anaconda3\Library\mingw-w64\bin;C:\Users\Ivo\Anaconda3\Library\usr\bin;C:\Users\Ivo\Anaconda3\Library\bin;C:\Users\Ivo\Anaconda3\Scripts;C:\Users\Ivo\AppData\Local\Programs\Python\Python36-32\Scripts\;C:\Users\Ivo\AppData\Local\Programs\Python\Python36-32\;C:\Users\Ivo\AppData\Local\Microsoft\WindowsApps;C:\Users\Ivo\AppData\Roaming\Composer\vendor\bin;C:\Users\Ivo\AppData\Local\atom\bin;C:\scrcpy-windows-v1.0\adb.exe;D:\xampp2\php;C:\Users\Ivo\AppData\Roaming\npm;

如果有人能帮助我/指出正确的方向,我会整整一天的努力。

编辑:

此外,由于我已经重新安装了一些东西来尝试解决此问题。该文件将无法启动并出现以下错误:

Traceback (most recent call last):
  File "C:\Users\Ivo\Documents\temp\project\gui.py", line 9, in <module>
    from PyQt5 import QtCore, QtGui, QtWidgets
ImportError: DLL load failed: The specified procedure could not be found.

5 个答案:

答案 0 :(得分:6)

Conda 4.5.11, Python 3.6.4, PyInstaller 3.4

在hooks / qt.py中错误地确定了插件路径。 Qt要求先进行QCoreApplication实例化,然后再进行其他调用。

我的qt.py挂钩位于〜\ anaconda3 \ Lib \ site-packages \ PyInstaller \ utils \ hooks \ qt.py中。

我这样编辑它:

    json_str = exec_statement("""
        import sys

        # exec_statement only captures stdout. If there are
        # errors, capture them to stdout so they can be displayed to the
        # user. Do this early, in case PyQt5 imports produce stderr
        # output.
        sys.stderr = sys.stdout

        import json
        from %s.QtCore import QLibraryInfo, QCoreApplication

        # QLibraryInfo isn't always valid until a QCoreApplication is
        # instantiated.
        app = QCoreApplication([])
        paths = [x for x in dir(QLibraryInfo) if x.endswith('Path')]
        location = {x: QLibraryInfo.location(getattr(QLibraryInfo, x))
                    for x in paths}
        try:
            version = QLibraryInfo.version().segments()
        except AttributeError:
            version = None
        print(str(json.dumps({
            'isDebugBuild': QLibraryInfo.isDebugBuild(),
            'version': version,
            'location': location,
        })))
    """ % self.namespace)

请参见1

答案 1 :(得分:1)

我正在将Python 3.6.3与ANACONDA3和Spyder用作IDE。 Pyinstaller 3.4。

尝试使用 Pyinstaller 生成exe文件时,出现两种错误:

  1. ” AttributeError:“ str”对象没有属性“ items”” 。这是由解决      更新在Python脚本中导入的每个模块,其中包括:                pip install --upgrade << em> module_name >
  2. “找不到现有的PyQt5插件目录” :这是下一个错误。如   cong yu 在他的上一篇文章中提到的,我通过运行来解决此问题                pip安装PyQt5

  3. 不要忘记将 setuptools 升级到最新版本

进程提供了一个我尚未测试过的exe文件。 但是至少,我成功地将Pyinstaller推到了尽头,而不会出错。

希望这会有所帮助

顺便说一句,新年快乐:)

修改

我已经测试了由 py2exe 生成的独立的 .exe 该程序正在运行,并且没有任何错误。

但是问题是 xlsx 不再运行,因为没有Excel 文件已创建。这些文件基于 pandas 数据框。 我的提示是 pandas 模块,它是程序的主要核心, 似乎被改变了。我注意到所使用的数据帧被截断了, 通过在 Spyder 中的 Ipython 控制台中编辑的控制行。

我认为我最好的选择是重新安装 Anaconda3

因此请小心,升级所需程序中使用的模块 py2exe 独立运行。似乎升级熊猫模块是一个 错误。

很抱歉,如果我在主要帖子中给出了错误的建议,但是升级是 运行 py2exe 的最佳方法。升级熊猫时要小心。

答案 2 :(得分:0)

尝试卸载Anaconda。过去有过问题。如果没有,您也可以尝试相当不错的py2exe。

答案 3 :(得分:0)

尝试Exception: Cannot find PyQt5 plugin directories when using Pyinstaller despite PyQt5 not even being used中的修复程序。简而言之:

pip intall PyQt5

请注意,conda install PyQt5可能无法解决问题。

我遇到了同样的问题,并看到了另一个建议:创建丢失的目录(在您的情况下为C:/ qt5b / qt_1524647842210 / _h_env / Library / plugins),然后复制两个文件pyqt5.dll和pyqt5qmlplugin.dll(大概在c:\ Users [名称] \ AppData \ Local \ conda \ conda \ envs)到目录。

我没有尝试过,因为我解决了pip install PyQt5的问题。您可能需要尝试一下。

答案 4 :(得分:0)

我安装了最新版本的PyInstaller ,然后{strong>已解决这个"Cannot find existing PyQt5 plugin directories"例外。

您可以通过following command安装最新版本的PyInstaller:

pip install https://github.com/pyinstaller/pyinstaller/tarball/develop
  

P.S:有关我的设置的一些信息:

$conda info
      conda version : 4.6.14
conda-build version : 3.17.8
     python version : 3.7.3.final.0
           platform : win-64
         user-agent : conda/4.6.14 requests/2.21.0 CPython/3.7.3 Windows/10 Windows/10.0.17763

$ pip show pyinstaller
Name: PyInstaller
Version: 3.5.dev0+d74052489
Summary: PyInstaller bundles a Python application and all its dependencies into a single package.