好的,我开发了一个PySide桌面应用程序,我想使用 cx_Freeze 进行共享。我在打包 paramiko 库时遇到了一些问题,但我使用此workaround解决了。
一切都在我的计算机上运行,这意味着双击cx_Freeze生成的.exe应用程序正在启动并正常工作。
当我在朋友的PC上测试该包装时,感到非常失望。
该应用无法启动并显示此错误:
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_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")]}
问题是,正如我从朋友的PC上发布的错误所示,该程序正在我的PC路径上寻找那些DLL!
您可以提出其他解决方案吗?我尝试了包括的所有东西:
这是我的setup.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])
答案 0 :(得分:1)
在GitHub repository of cryptography上查找,导致错误的行似乎是:
__import__("_ssl")
因此,您朋友的PC上可能缺少_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']}
关于您的声明:
问题是,正如我从朋友电脑上发布的错误所示,该程序正在我的电脑路径上寻找那些dll!
您可能会对回溯中显示的路径产生误解:这些是附加到代码对象的文件名,它们在冻结的应用程序移动时可能无法实现。有关更多详细信息,请参见我对How to fix numpy dependencies path on a python 3.7.3 script on Linux frozen with cx_Freeze 6.0b1?的回答,以及一个cx_Freeze选项,该选项允许在冻结时实现路径。