Skip to main content
 首页 » 编程设计

python + cx_freeze 'cannot get zipimporter instance'

2024年10月24日13zhoujg

我看到了one question与此相关,但它并没有真正回答我的问题。

我编写了一个程序,旨在无需安装 python 即可使用;我使用 cx_freeze 来实现这一点。我写了一个setup.py,在cmd里运行。这一切都很好,虽然我确实收到了一些“缺少模块”的警告,但它向我保证这可能不是问题:

    Missing modules: 
? _dummy_threading imported from dummy_threading 
? ce imported from os 
? doctest imported from heapq 
? getopt imported from base64, quopri 
? grp imported from shutil, tarfile 
? org.python.core imported from copy 
? os.path imported from os, py_compile, shutil 
? posix imported from os 
? pwd imported from posixpath, shutil, tarfile 
? subprocess imported from os 
This is not necessarily a problem - the modules may not be needed on this platform. 

(我运行的是 Windows 8,从来没有抽出时间更新到 8.1)

导出后,我看到两个文件; 'python34.dll' 和 'T-Backup.exe'。当我运行 T-backup.exe 时出现上述错误。

这是我的 setup.py,以备不时之需:

import sys 
from cx_Freeze import setup, Executable 
 
base = None 
if (sys.platform == "win32"): 
    base = "Win32GUI" 
 
exe = Executable( 
        script = "<path>\\T-Backup.py", 
        icon = "<path>\\Icon.ico", 
        targetName = "<path>\\exe\\T-Backup.exe", 
        base = base 
        ) 
includefiles = ["<path>\\Icon.ico","<path>\\backupfrom.tbk","<path>\\backupto.tbk"] 
 
setup( 
    name = "T-Backup", 
    version = "0.1", 
    description = "Backs up Terraria Worlds and Players.", 
    author = "Sam Poirier (darthmorf)", 
    options = {'build_exe': {'include_files':includefiles}}, 
    executables = [exe] 
 
 
 
) 

感谢您的帮助。

-达斯莫夫

请您参考如下方法:

我不能评论,所以我回答:

我认为你在 64 位系统上,你永远不会得到除“无”之外的基数。尝试改变

base = None 
if (sys.platform == "win32"): 
    base = "Win32GUI" 

到

base = "Win32GUI" 

这解决了我的很多问题,这些问题与您描述的类似...

如果您能展示您实际导入了哪些模块,那么我可能会有更多用处。