首页 > 解决方案 > 没有使用 cx_Freeze 冻结模块 _cffi_

问题描述

我正在开发一个 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包有关。有没有人遇到并解决了这个问题?

标签: pythonparamikocx-freeze

解决方案


我想我通过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. 明确指定cffiand cryptographyin的导入build_exe_options
  2. 复制l的dll和libcrypto-1_1-x64.dllibssl-1_1-x64.dll
  3. 明确指定后端作为openssl_backend而不是default_backend

推荐阅读