[英]cx_freeze embedding my shared object library into the binary executable?
I'm able to use cx_freeze to package my python tool, but the library I need can't be loaded. 我可以使用cx_freeze打包我的python工具,但是我需要的库无法加载。 For some reason the outputted executable/binary name keeps getting included in the path.
由于某种原因,输出的可执行文件/二进制名称不断包含在路径中。
I get the following error: 我收到以下错误:
OSError: /home/derekx/sbu/build/exe.linux-x86_64-2.7/secure_boot_utility/lib/libcrypto.so.1.0.0: cannot open shared object file: Not a directory OSError:/home/derekx/sbu/build/exe.linux-x86_64-2.7/secure_boot_utility/lib/libcrypto.so.1.0.0:无法打开共享对象文件:不是目录
The library gets packaged to /home/derekx/sbu/build/exe.linux-x86_64-2.7/lib/libcrypto.so.1.0.0 该库被打包到/home/derekx/sbu/build/exe.linux-x86_64-2.7/lib/libcrypto.so.1.0.0
The created binary "secure_boot_utility" is also in the build/exe.linux86_64-2.7 dir. 创建的二进制文件“secure_boot_utility”也位于build / exe.linux86_64-2.7目录中。
My input script and setup.py are in /home/derekx/sbu. 我的输入脚本和setup.py位于/ home / derekx / sbu中。
I used "python setup.py build" to package the tool/dependencies.. 我使用“python setup.py build”来打包工具/依赖项。
Any help would be greatly appreciated. 任何帮助将不胜感激。 I've tried a combination of the options but still get the same error.
我尝试了一些选项的组合,但仍然得到相同的错误。
My setup.py is: 我的setup.py是:
import sys
from cx_Freeze import setup, Executable
sys.path.append('sbu_scripts/')
sys.path.append('lib/')
binincludes = ['libcrypto.so.1.0.0']
binpaths = ['/home/derekx/sbu/lib']
includefiles = [('lib/libcrypto.so.1.0.0','lib/libcrypto.so.1.0.0'),]
exe = Executable(
script="secure_boot_utility.py",
)
setup(
name = "SecureBoot",
version = "0.1",
description = "Test Secure Boot",
options = {"build_exe": {'copy_dependent_files':True, 'create_shared_zip':True, 'bin_includes':binincludes, 'bin_path_includes':binpaths, 'include_files':includefiles}},
executables = [exe]
)
I'm not sure why the top level directory (getcwd) is the executable name. 我不确定为什么顶级目录(getcwd)是可执行文件名。
Anyway I was able to add something in my code with os.path.exists and readjust the value sent to LoadLibrary. 无论如何,我能够使用os.path.exists在我的代码中添加一些东西,并重新调整发送给LoadLibrary的值。
Thanks, Thomas, for taking the time to respond. 谢谢,托马斯,花时间回应。
This is originally someone else's tool that I had to support. 这本来是我必须支持的其他人的工具。 What was happening was sys.path[0] was being used to get the current working directory to construct the full path to the libraries being loaded.
发生了什么是sys.path [0]用于获取当前工作目录以构建正在加载的库的完整路径。 I'm not sure why the executable that was created with cx_freeze always embedded the executable name in the the current working directory.
我不确定为什么用cx_freeze创建的可执行文件总是在当前工作目录中嵌入可执行文件名。
How I fixed it, was checked if the full path of the library that gets constructed existed with os.path.exists: 如何修复它,检查了构造的库的完整路径是否存在于os.path.exists中:
if os.path.exists(path_to_lib) is False:
path_to_lib = LibName
return path_to_lib
This way if the full path exists, it works and if it does not just use the LibName which should pick it up from the LD_LIBRARY_PATH environment setting. 这样,如果存在完整路径,它就可以工作,如果它不只是使用LibName,它应该从LD_LIBRARY_PATH环境设置中获取它。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.