创建一个独立的Linux可执行文件,从Python代码中。

huangapple go评论69阅读模式
英文:

Creating a standalone linux exe from Python code

问题

我们正在尝试创建一个单独的可执行文件版本,该版本可以在Ubuntu 16.x到22.x以及RedHat 7.2上运行我们的Python应用程序。

目前,我们正在使用两步骤的过程在Ubuntu 22.04上构建:

  1. 使用PyInstaller创建一个单一的可执行文件(其中包括捆绑我们的应用程序使用的一些其他二进制工具)。
  2. 使用staticx来静态链接可执行文件使用的所有库。

然而,我们遇到了问题。例如,在Ubuntu 16.04上运行并生成二进制工具时,我们会收到如下错误:

/lib/x86_64-linux-gnu/libc.so.6: 找不到版本 'GLIBC_2.34'(由 /tmp/_MEIvDsZl/libgcc_s.so.1 要求)

因此,二进制工具正在使用由staticx捆绑的libgcc_s.so.1,但它需要一个不存在的libc.so.6。

我尝试过使用staticx的-l参数将libc.so.6从构建机器添加进去,但似乎没有任何改善。

所以:

  1. 有人知道如何使staticx生成在这种情况下能够工作的可执行文件吗?
  2. 有没有替代staticx的方法,可以生成适用于所有操作系统的可执行文件,包括捆绑和生成二进制工具?
英文:

We are trying to create a single standalone exe version of our Python application which will run on Ubuntu versions 16.x to 22.x and also on RedHat 7.2.

Currently we're building on Ubuntu 22.04 using a two step process

  1. PyInstaller to make a single exe (this includes bundling some other binary tools that our app uses)
  2. staticx to statically link all libraries that the exe uses.

However we are seeing problems. E.g. when running on Ubuntu 16.04 and spawning the binary tools, we get errors like:

/lib/x86_64-linux-gnu/libc.so.6: version 'GLIBC_2.34' not found (required by /tmp/_MEIvDsZl/libgcc_s.so.1)

So the binary tool is using the libgcc_s.so.1 bundled by staticx but then it requires a libc.so.6 that doesn't exist.

I've tried adding the libc.so.6 from the build machine using staticx's -l argument but that seems to make no difference.

So

  1. Does anyone know how we can get staticx to produce an exe that will work in this situation?
  2. Are there any alternatives to staticx that will produce an exe that will work for all our OSs, including bundling and spawning the binary tools?

答案1

得分: 0

这似乎更多是与PyInstaller相关,而不是StaticX(尽管我们仅使用PyInstaller时从未遇到问题)。这解决了问题:

https://pyinstaller.org/en/stable/runtime-information.html?highlight=LD_LIBRARY_PATH#ld-library-path-libpath-considerations

英文:

It seems that the problem is more an issue with PyInstaller than StaticX (though we never had a problem when just using PyInstaller). This solves the problem:

https://pyinstaller.org/en/stable/runtime-information.html?highlight=LD_LIBRARY_PATH#ld-library-path-libpath-considerations

huangapple
  • 本文由 发表于 2023年6月1日 20:40:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76381964.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定