我对phyton很陌生,刚刚完成了我的第一个应用程序。
现在,我正在尝试将.py文件编译为似乎无法正常工作的.exe购买。
我到处都在寻找解决方案,但我似乎找不到。
当我运行此命令时:pyinstaller gui.py
出现此错误:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
564815 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
unpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File"c:\users\ivo\anaconda3\lib
unpy.py", line 85, in _run_code
exec(code, run_globals)
File"C:\Users\Ivo\Anaconda3\Scripts\pyinstaller.exe\__main__.py", line 9, in
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"", line 17, in
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"", line 399, in _check_name_wrapper
File"", line 823, in load_module
File"", line 682, in load_module
File"", line 265, in _load_module_shim
File"", line 684, in _load
File"", line 665, in _load_unlocked
File"", line 678, in exec_module
File"", line 219, in _call_with_frames_removed
File"c:\users\ivo\anaconda3\lib\site-packages\PyInstaller\hooks\hook-PyQt5.QtGui.py", line 11, in
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
我的路径变量:
1
2
3
4C:\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
oaming\Composer\vendor\bin;C:\Users\Ivo\AppData\Local\atom\bin;C:\scrcpy-windows-v1.0\adb.exe;D:\xampp2\php;C:\Users\Ivo\AppData
oaming
pm;
如果有人能帮助我/指出正确的方向,我会整天整天解决这个问题。
编辑:
另外,由于我已经重新安装了一些东西来尝试解决此问题。 该文件将无法启动,并出现以下错误:
1
2
3
4Traceback (most recent call last):
File"C:\Users\Ivo\Documents\temp\project\gui.py", line 9, in
from PyQt5 import QtCore, QtGui, QtWidgets
ImportError: DLL load failed: The specified procedure could not be found.
康达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中。
我这样编辑它:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28json_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。
太棒了,此代码有效!非常感谢!
如何在不从conda环境中编辑钩子的情况下做到这一点?通过更新qt之类的东西? .py文件本身让我感到非常不舒服
我距离专家还很远,但是我找不到其他方法可以使它工作。
我正在将Python 3.6.3与ANACONDA3和Spyder用作IDE。 Pyinstaller 3.4。
尝试使用Pyinstaller生成exe文件时,出现两种错误:
" AttributeError:'str'对象没有属性'items'"。这是由解决
使用以下命令更新Python脚本中导入的每个模块:
pip install --upgrade
"找不到现有的PyQt5插件目录":这是下一个错误。如
于聪在之前的文章中提到过,我通过运行来解决此问题
点安装PyQt5
不要忘记也将setuptools升级到最新版本
该过程提供了一个我尚未测试过的exe文件。
但是至少,我成功地将Pyinstaller推到了尽头,没有出错。
希望这会有所帮助
顺便说一句,新年快乐:)
编辑:
我已经测试了py2exe生成的独立.exe
该程序正在运行,并且没有错误地结束。
但是问题在于xlsx不再运行,因为没有Excel
文件已创建。这些文件基于pandas数据框。
我的提示是熊猫程序模块,它是程序的主要核心,
似乎被改变了。我注意到所使用的数据帧被截断了,
通过在Spyder的Ipython控制台中编辑的控制线。
我认为我最好的选择是重新安装Anaconda3。
因此请小心,升级所需程序中使用的模块
与py2exe独立运行。似乎升级熊猫模块是一个
错误。
很抱歉,如果我在主要帖子中给出了错误的建议,但是升级是
运行py2exe的最佳方法。升级熊猫时要小心。
请尝试以下异常中的修复程序:使用Pyinstaller时找不到PyQt5插件目录,尽管甚至没有使用PyQt5。简而言之:
pip intall PyQt5
请注意,奇怪的是,conda install PyQt5可能无法解决问题。
我遇到了同样的问题,并看到了另一个建议:创建丢失的目录(在您的情况下为C:/ qt5b / qt_1524647842210 / _h_env / Library / plugins),然后复制两个文件pyqt5.dll和pyqt5qmlplugin.dll(大概在c:中的某个位置)用户[名称] AppData Local conda conda envs)到目录。
我没有尝试过,因为我修复了pip install PyQt5的问题。您可能需要尝试一下。
该奇怪的子目录名称从何而来? (在您的情况下,其C:qt5bqt_1524647842210_h_envLibraryplugins)?这个问题并不直接针对您,而是针对任何阅读此问题的人。我得到了一个完全不同的目录,但是"创建怪异目录"解决方案也对我有用(不仅仅是安装)
由于该异常被投诉:异常:找不到现有的PyQt5插件目录检查的路径:C:/ qt5b / qt_1524647842210 / _h_env / Library / plugins
@ cong you-我的评论应该更加清楚。这不是给你的。我在问是否其他人知道您的消息中的目录为什么与我的目录不同,即使它的消息基本相同。 pyinstaller如何创建该目录名,因为您的目录名与我的不同,并且在我的系统中都不存在。
我安装了最新版本的PyInstaller,然后解决了"Cannot find existing PyQt5 plugin directories"的此异常。
您可以通过以下命令安装最新版本的PyInstaller:
1pip install https://github.com/pyinstaller/pyinstaller/tarball/develop
P.S: Some information about my setup:
1
2
3
4
5
6
7
8
9
10
11$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.
尝试卸载Anaconda。过去有过问题。如果没有,您也可以尝试相当不错的py2exe。