cx\u冻结包在另一台机器上不起作用

2024-09-30 00:36:45 发布

您现在位置:Python中文网/ 问答频道 /正文

好的,我开发了一个PySide桌面应用程序,我想用cx\u Freeze来共享它。我在打包paramiko库时遇到了一些问题,但是我用这个workaround解决了这个问题。你知道吗

一切都在我的机器上运行,这意味着双击cx\u Freeze生成的.exe,应用程序启动并正常工作。你知道吗

当我在朋友的电脑上测试这个软件包时,我感到非常失望

应用程序未启动并显示此错误:

File "C:\Users\frpegora\AppData\Local\Programs\Python\Python37\lib\site-packages\cx_Freeze\initscripts\__startup__.py", line 14, in run
  File "C:\Users\frpegora\AppData\Local\Programs\Python\Python37\lib\site-packages\cx_Freeze\initscripts\Console.py", line 26, in run
  File "main_window.py", line 13, in <module>
  File "C:\Users\frpegora\Desktop\Projects\GUI\single_widget.py", line 13, in <module>
  File "C:\Users\frpegora\Desktop\Projects\GUI\importer_server.py", line 14, in <module>
  File "C:\Users\frpegora\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\__init__.py", line 22, in <module>
  File "C:\Users\frpegora\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\transport.py", line 90, in <module>
  File "C:\Users\frpegora\AppData\Local\Programs\Python\Python37\lib\site-packages\paramiko\ed25519key.py", line 20, in <module>
  File "C:\Users\frpegora\AppData\Local\Programs\Python\Python37\lib\site-packages\cryptography\hazmat\backends\openssl\__init__.py", line 7, in <module>
  File "C:\Users\frpegora\AppData\Local\Programs\Python\Python37\lib\site-packages\cryptography\hazmat\backends\openssl\backend.py", line 71, in <module>
  File "C:\Users\frpegora\AppData\Local\Programs\Python\Python37\lib\site-packages\cryptography\hazmat\bindings\openssl\binding.py", line 195, in <module>
  File "C:\Users\frpegora\AppData\Local\Programs\Python\Python37\lib\site-packages\cryptography\hazmat\bindings\openssl\binding.py", line 142, in init_static_locks
ImportError: DLL load failed: The specified module could not be found.

我以为已经解决的问题又回来了!你知道吗

更确切地说,前一段时间,我在setup.py中为cx\u Freeze传递了paramiko所需的dll:

PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))

build_exe_options = {"packages": ['cffi', 'cryptography'],
                     '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")]}

问题是,如我在朋友的电脑上发布的错误所示,程序正在我的电脑路径上查找那些DLL!你知道吗

你能提出不同的解决方案吗?我什么都试过了包括:

  • 手动传递DLL
  • 复制错误中显示的整个文件夹

这是我的设置.py地址:

from cx_Freeze import setup, Executable 
import os.path

PYTHON_INSTALL_DIR = os.path.dirname(os.path.dirname(os.__file__))

build_exe_options = {"packages": ['cffi', 'cryptography'], 'include_files': [ ('libssl-1_1-x64.dll', os.path.join('lib', 'libssl-1_1-x64.dll')),
 ('libcrypto-1_1-x64.dll', os.path.join('lib', 'libcrypto-1_1-x64.dll'))]}


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

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

Tags: inpyoslibpackageslocallinesite
1条回答
网友
1楼 · 发布于 2024-09-30 00:36:45

GitHub repository of cryptography上看,导致错误的行似乎是:

__import__("_ssl")

因此,您朋友的电脑上可能缺少_ssl。请尝试添加

import _ssl

或修改设置脚本中的build_exe_options,如下所示:

build_exe_options = {"packages": ['cffi', 'cryptography'],
                     '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")],
                     'includes': ['_ssl']}

关于你的陈述:

The problem is that as shown in the error I posted from my friend's pc, the program is looking for those dlls on my PC's path!

您可能会被回溯中显示的路径所误导:这些是附加到代码对象的文件名,当冻结的应用程序被移动时,这些文件名可能不会实现。有关更多详细信息,请参阅我对How to fix numpy dependencies path on a python 3.7.3 script on Linux frozen with cx_Freeze 6.0b1?的回答,以及允许在冻结时实现路径的cx\u冻结选项。你知道吗

相关问题 更多 >

    热门问题