我正在尝试使用cx_Freeze创建 .exe 。当我尝试构建它时,它将引发值错误。我不明白这到底意味着什么。您认为重新安装cx_Freeze是否可以解决问题?
setup.py 如下:
from cx_Freeze import setup, Executable
import os
import sys
base = None
if sys.platform == 'win32':
base = 'Win32GUI'
exe = [Executable("main.py", base=base)]
os.environ['TCL_LIBRARY'] = r'C:\\Users\\dm\\AppData\\Local\\Programs\\Python\\Python36\\tcl\\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\\Users\\dm\\AppData\\Local\\Programs\\Python\\Python36\\tcl\\tk8.6'
options = {
'build_exe': {
'includes': ['scipy.io', 'scipy.spatial.ckdtree'],
'include_files': [r'C:\\Users\\dm\\AppData\\Local\\Programs\\Python\\Python36\\DLLs\\tcl86t.dll', r'C:\\Users\\dm\\AppData\\Local\\Programs\\Python\\Python36\\DLLs\\tk86t.dll',
r'C:\\Users\\dm\\AppData\\Local\\Programs\\Python\\Python36\\Lib\\site-packages\\pyqt5_tools\\platforms\\qwindows.dll'],
'packages': ['pandas', 'numpy', 'scipy', 'pydub', 'librosa', 'PyQt5.QtCore', 'PyQt5.QtGui', 'PyQt5.QtWidgets',
'python_speech_features'],
}
}
setup(name="GUI", version="1.0", description='To be added',
options=options, executables=exe)
在构建它时,出现以下错误。
running build
running build_exe
Traceback (most recent call last):
File "setup.py", line 38, in <module>
options=options, executables=exe)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\dist.py", line 349, in setup
distutils.core.setup(**attrs)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\distutils\dist.py", line 955, in run_commands
self.run_command(cmd)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\distutils\command\build.py", line 135, in run
self.run_command(cmd_name)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\distutils\dist.py", line 974, in run_command
cmd_obj.run()
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\dist.py", line 219, in run
freezer.Freeze()
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\freezer.py", line 616, in Freeze
self.finder = self._GetModuleFinder()
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\freezer.py", line 340, in _GetModuleFinder
finder.IncludeModule(name)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 651, in IncludeModule
namespace = namespace)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 311, in _ImportModule
deferredImports, namespace = namespace)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 385, in _InternalImportModule
namespace = namespace)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 404, in _InternalImportModule
parentModule, namespace)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 417, in _LoadModule
namespace)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 486, in _LoadPackage
self._LoadModule(name, fp, path, info, deferredImports, parent)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 464, in _LoadModule
self._RunHook("load", module.name, module)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 537, in _RunHook
method(self, *args)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\hooks.py", line 567, in load_scipy
finder.IncludePackage("scipy.misc")
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 659, in IncludePackage
module = self._ImportModule(name, deferredImports)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 311, in _ImportModule
deferredImports, namespace = namespace)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 404, in _InternalImportModule
parentModule, namespace)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 417, in _LoadModule
namespace)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 486, in _LoadPackage
self._LoadModule(name, fp, path, info, deferredImports, parent)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 475, in _LoadModule
self._ScanCode(module.code, module, deferredImports)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 565, in _ScanCode
module, relativeImportIndex)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 346, in _ImportModule
deferredImports, namespace = namespace)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 404, in _InternalImportModule
parentModule, namespace)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 475, in _LoadModule
self._ScanCode(module.code, module, deferredImports)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 570, in _ScanCode
fromList, deferredImports)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 211, in _EnsureFromList
self._ImportModule(subModuleName, deferredImports, caller)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 311, in _ImportModule
deferredImports, namespace = namespace)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 404, in _InternalImportModule
parentModule, namespace)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 475, in _LoadModule
self._ScanCode(module.code, module, deferredImports)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 589, in _ScanCode
topLevel = False)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 589, in _ScanCode
topLevel = False)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 570, in _ScanCode
fromList, deferredImports)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 211, in _EnsureFromList
self._ImportModule(subModuleName, deferredImports, caller)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 311, in _ImportModule
deferredImports, namespace = namespace)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 404, in _InternalImportModule
parentModule, namespace)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 475, in _LoadModule
self._ScanCode(module.code, module, deferredImports)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 565, in _ScanCode
module, relativeImportIndex)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 311, in _ImportModule
deferredImports, namespace = namespace)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 404, in _InternalImportModule
parentModule, namespace)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 464, in _LoadModule
self._RunHook("load", module.name, module)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\finder.py", line 537, in _RunHook
method(self, *args)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\hooks.py", line 526, in load_PyQt4_QtGui
name, QtCore = _qt_implementation(module)
File "C:\Users\dm\AppData\Local\Programs\Python\Python36\lib\site-packages\cx_Freeze\hooks.py", line 437, in _qt_implementation
_qtcore = __import__(name, fromlist=['QtCore']).QtCore
ValueError: PyCapsule_GetPointer called with incorrect name
感谢您的帮助。
答案 0 :(得分:1)
您的安装脚本包括属于tkinter
和PyQt5
的文件和软件包,并且您发布的堆栈跟踪显示执行安装钩子的PyQt4
时安装脚本失败。 ,这表明您的主脚本在某处导入了PyQt4
。从tkinter
,PyQt4
和PyQt5
中选择一个GUI库,并在整个主脚本和设置脚本中仅使用选定的GUI库。
您可以将不使用的库添加到'excludes'
选项字典的build_exe
列表项中,以告诉cx_Freeze
不要包含它们。