使用 py2exe 编译后程序无法运行

program wont work after being compiled with py2exe

我写了一个程序,当我从 python 解释器 运行 时,它工作正常,没有任何错误,然后我使用 py2exe 将它转换为 .exe,但是当我 运行 它不再工作了...我收到此错误:

Traceback (most recent call last):
 File "pass.py", line 1, in <module>
 File "dropbox\__init__.pyc", line 3, in <module>
 File "dropbox\client.pyc", line 22, in <module>
 File "dropbox\rest.pyc", line 26, in <module>
 File "pkg_resources.pyc", line 950, in resource_filename
 File "pkg_resources.pyc", line 1638, in get_resource_filename
NotImplementedError: resource_filename() only supported for .egg, not .zip

当我下载了导入程序的模块后,我是否应该在使用 py2exe 时做些什么? 这些是导入的模块:

import dropbox
import os
import getpass
from time import sleep

请帮忙!

我使用找到的解决方案解决了这个问题 here

基本上你修改 ~line 26 in rest.py find in the dropbox library 对此:

try:  
    TRUSTED_CERT_FILE = pkg_resources.resource_filename(__name__, 'trusted-certs.crt')
except:  
    # if current module is frozen, use library.zip path for trusted-certs.crt path
    # trusted-certs.crt must exist in same directory as library.zip
    if hasattr(sys,'frozen'):
        resource_name = sys.prefix
        resource_name.strip('/')
        resource_name += '/trusted-certs.crt'
        TRUSTED_CERT_FILE = resource_name
    else:
        raise

然后将同样在 Dropbox 库中找到的受信任的 certs.crt 文件放在与您的可执行文件相同的文件夹中