简体   繁体   中英

Does python + pyinstaller support multiple OS/Versions of linux?

I have written several small scripts in python and build the binaries using pyinstaller.

When I would build them on my Ubuntu 16.04 machine -- they would run fine on the machine where I build them. But moving the file to a Centos / Redhat 7.4 machine would give me GCLIB and other .so version dependency errors.

  • Building the same binary on docker with the same version of Centos would not give these errors.
  • If I try running the binary compiled on Centos 7.4 on Centos 6.6 I would get errors again -- But building on Centos 6.6 it would work correctly with Centos 6.6

I have solved the problem using a lower version of Centos to build my binaries for now.

  • My specific question is -- In Python, is it a common approach of building the binaries on different OSs based on the target OS that it is intended for (assuming linux targets only) or what I am doing is a hack / bad way of solving this problem?

I am trying to understand how this problem is approached in the standard way.

As long as the binary produced by pyinstaller only depends on glibc, then it should be a valid approach to build it on the oldest system available, and it should work on future systems.

In general, glibc is designed to be backwards compatible, so that applications built against an older version of glibc will still run with a newer glibc, but not vice versa. It does this via symbol versioning, in which each symbol you link to can have a version associated with it, and any case in which a newer glibc has changed the ABI of some function, it will also have a compatibility routine with the old ABI exposed with the older symbol version, so that applications linked against the old one will dynamically link with the compatibility routine, while if you have an application linked against the newer symbol versions, there won't be the newer versions in an older glibc to dynamically link to.

While other libraries can also do this, not many library authors bother to, so newer versions may simply be incompatible, while the glibc developers generally try to preserve compatibility.

So yes, as long as the final binary links only to glibc, or to other libraries which follow a similar symbol versioning scheme to ensure that older binaries will still link properly to newer versions of the library, it is perfectly valid to build against an older version and then run it on newer versions of various Linux distros, and even generally across distros as well.

Unfortunately, there's no good way to get the linker to pick the older symbol versions if linking against a newer glibc, so frequently the easiest way to do this is within a Docker or other type of container containing an older distro that has the oldest glibc that you want to be compatible with.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM