【问题标题】:No module _cffi_ freezing with cx_Freeze没有使用 cx_Freeze 冻结模块 _cffi_
【发布时间】:2019-05-09 09:20:42
【问题描述】:

我正在开发一个 PySide 应用程序(Qt for Python),我想使用 cx_Freeze 冻结它。

当我使用下面的设置文件运行python setup.py build 时,它会创建没有错误的构建目录,但是当我运行生成的 .exe 文件时,我收到如下所示的错误消息:

from cx_Freeze import setup, Executable 

target = Executable(
    script="main_window.py",
    base = "Win32GUI",
    icon="images\\icon.ico"
    )

setup(name = "DemiurgoXMLgen" , 
    version = "0.1" , 
    description = "" ,
    options={'build_exe': {'include_files': ['images\\']}},
    executables = [target])

我认为这与我在应用程序中使用的 Paramiko 包有关。有没有人遇到并解决过这个问题?

【问题讨论】:

  • 请将错误信息以文字形式而非图片形式发布,请参阅Why not upload images of code on SO when asking a question?
  • 是的,我知道,我这样发布它是因为 Windows 不允许我将其复制为文本 :(
  • 是的,我知道,然后你需要输入,这很烦人......或者使用例如Console2,允许您选择和复制文本:)

标签: python paramiko cx-freeze


【解决方案1】:

我想我通过如下修改setup.py解决了这个问题:

import os.path

PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))
build_exe_options = {"include_files" : [
    os.path.join(PYTHON_INSTALL_DIR, "DLLs", "libcrypto-1_1-x64.dll"),
    os.path.join(PYTHON_INSTALL_DIR, "DLLs", "libssl-1_1-x64.dll")]}
build_exe_options = {"packages": ['cffi', 'cryptography'], 'include_files': ['images\\', os.path.join(PYTHON_INSTALL_DIR, "DLLs", "libcrypto-1_1-x64.dll"),
    os.path.join(PYTHON_INSTALL_DIR, "DLLs", "libssl-1_1-x64.dll")]}

target = Executable(
    script="main_window.py",
    base = "Win32GUI",
    icon="images\\icon.ico"
    )

setup(name = "DemiurgoXMLgen" , 
    version = "0.1" , 
    description = "" ,
    options={'build_exe': build_exe_options},
    executables = [target])

并在paramiko->ed25519key.py 中修改导入:

从 cryptography.hazmat.backends 导入 default_backend

from cryptography.hazmat.backends import openssl as openssl_backend

基本上:

  1. build_exe_options中明确指定cfficryptography的导入
  2. 复制libcrypto-1_1-x64.dll 和libssl-1_1-x64.dlldll
  3. 明确指定后端为openssl_backend 而不是default_backend

【讨论】:

    猜你喜欢
    • 2013-07-27
    • 1970-01-01
    • 1970-01-01
    • 2017-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-30
    相关资源
    最近更新 更多