【问题标题】:py2exe MemoryLoadLibrary failed loading _ssl.pyd, Win7<->Win10py2exe MemoryLoadLibrary 加载_ssl.pyd 失败,Win7<->Win10
【发布时间】:2016-05-17 10:25:10
【问题描述】:

简介

我有一个使用 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 时它突然起作用了。 但我不明白为什么。

我的设置

  • python 32bit 2.7.11
  • ssl.OPENSSL_VERSION => 'OpenSSL 1.0.2d 2015 年 7 月 9 日'
  • py2exe 0.6.9

在两台机器上都一样(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)

【问题讨论】:

    标签: python python-2.7 ssl py2exe


    【解决方案1】:

    将“crypt32.dll”和“mpr.dll”添加到您的 dll_excludes。这些由 _ssl.pyd 在较新版本的 Python(例如 2.7.11)中加载。但是这些库是 Windows 系统库和操作系统版本相关的,因此它们不应该与您的项目一起打包和分发。 Win7 "crypt32.dll" 可能适用于 Win10,但 Win10 "crypt32.dll" 很可能无法在 Win7 上运行。

    【讨论】:

    • 排除 crypt32.dll 成功了!我仍然不明白为什么:当 bundle_files 设置为 3 时,“dist”目录中有一个 crypt32.dll。为什么Win7不使用这个(win10版本),但是当它捆绑到*.exe时它被使用?我本来希望在运行 *.exe 时它会尝试使用其具有最高优先级的一个目录中的 *.dll 文件。
    猜你喜欢
    • 2014-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多