我有一个使用SSL的脚本,并使用py2exe构建(bundle_files = 1,将所有内容组合到* .exe中)
在Win7上运行py2exe会创建一个* .exe,它将在Win7和Win10中运行 在Win10上运行py2exe创建一个* .exe,它将在Win10中运行但在Win7中产生此错误:
ImportError: MemoryLoadLibrary failed loading _ssl.pyd
将bundle_files设置为3(不打包)将导致* .exe在Win7中工作正常,即使它是在Win10上构建的。
我尝试了一些py2exe选项,突然它改变了bundle_files。 但我不明白为什么。
两台机器上相同(win7和win10)。
demo.py
import ssl
print "import done"
可以使用这个构建 exebuilder.py
from distutils.core import setup
import py2exe
import sys
sys.argv.append("py2exe") # run py2exe (instead of supplying the command line argument)
# exclude some DLLs
dll_excludes = [
# win9x leftovers
"w9xpopen.exe",
# don't import these - otherwise win7 created *.exe won't work in winXP
# http://stackoverflow.com/questions/1979486/py2exe-win32api-pyc-importerror-dll-load-failed
"mswsock.dll",
"powrprof.dll"
]
sys.argv.append("--dll-excludes=%s" % ",".join(dll_excludes))
app_name = "win10ssl"
params = {
'zipfile': None, # pack everything into the *.exe
'options': {
"py2exe": {
"compressed": 1,
"optimize": 2,
# bundle_files
# 1 = EVERYTHING packed into the *.exe
# 2 = everything except for the pythonXX.dll
# 3 = don't pack
"bundle_files": 3
}
},
'version': "0.0.1.0",
'description': "demo to show MemoryLoadLibrary error",
'name': app_name,
'console': [{
"script": "demo.py",
"dest_base": app_name
}
]
}
setup(**params)
答案 0 :(得分:3)
将“crypt32.dll”和“mpr.dll”添加到dll_excludes。这些由_ssl.pyd在较新版本的Python(如2.7.11)中加载。但是这些库是Windows系统库和操作系统版本相关的,因此它们不应与您的项目一起打包和分发。 Win7“crypt32.dll”可能适用于Win10,但Win10“crypt32.dll”很可能无法在Win7上运行。