sno*_*odo 2 python ssl py2exe python-2.7
我有一个使用 SSL 的脚本,并使用 py2exe 构建(bundle_files=1,将所有内容打包到 *.exe 中)
在 Win7 上运行 py2exe 会创建一个 *.exe,它将在 Win7 和 Win10 中运行
在 Win10 上运行 py2exe 将创建一个 *.exe,它将在 Win10 中运行,但在 Win7 中会产生此错误:
ImportError: MemoryLoadLibrary failed loading _ssl.pyd
Run Code Online (Sandbox Code Playgroud)
将bundle_files设置为3(不打包)将生成一个*.exe,即使它是在Win10上构建的,它也可以在Win7中正常工作。
我尝试了一些 py2exe 选项,在更改 bundle_files 时突然它起作用了。但我不明白为什么。
两台机器上都一样(win7和win10)。
演示.py
import ssl
print "import done"
Run Code Online (Sandbox Code Playgroud)
可以使用这个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)
Run Code Online (Sandbox Code Playgroud)
小智 5
将“crypt32.dll”和“mpr.dll”添加到您的 dll_excludes 中。这些由 _ssl.pyd 在较新版本的 Python(例如 2.7.11)中加载。但这些库依赖于 Windows 系统库和操作系统版本,因此不应将它们与您的项目一起打包和分发。Win7“crypt32.dll”可能适用于Win10,但Win10“crypt32.dll”很可能不适用于Win7。
| 归档时间: |
|
| 查看次数: |
1697 次 |
| 最近记录: |