简体   繁体   中英

Compile python script on Windows for Linux use

is it possible to use pyinstaller on windows to compile a one-file solution for use on Linux?

On powershell, running the following command:

pyinstaller scriptname.py --onefile

works perfectly, creating a single .exe file that runs no problem on Windows. How can I modify this to produce a binary (or whatever it would be to run on Linux, I have no idea how to use that platform, I am just trying to get someone to test the code using that OS)?

I know part of the PyInstaller process is the creation of a .spec file, which can be modified for advanced configurations of compilation, but that is beyond me.

After searching online, it seems like PyInstaller has multi-platform capabilities, but some resources state that python scripts can only be compiled for use on the OS which it is being compiled on, so maybe it's not even possible, but I find it hard to believe that.

Thanks in advance for any help!

pyInstaller is not intended to be used as a cross-compiler, and has no support for doing so. In fact, this is the first answer in the FAQ :

  1. Can I use PyInstaller as a cross-compiler?

    1. Can I package Windows binaries while running under Linux?

      No, this is not supported. Please use ​Wine for this, PyInstaller runs fine in Wine. You may also want to have a look at ​this thread in the mailinglist. In version 1.4 we had build in some support for this, but it showed to work only half. It would require some Windows system on another partition and would only work for pure Python programs. As soon as you want a decent GUI (gtk, qt, wx), you would need to install Windows libraries anyhow. So it's much easier to just use Wine.

    2. Can I package OS X binaries while running under Linux?

      This is currently not possible at all. Sorry! If you want to help out, you are very welcome.

Of course you're asking if you can package Linux binaries while running under Windows, but, as you can guess, the answer is the same.

Even though pyInstaller itself can't do this, that doesn't necessarily mean it's impossible ; it's just that it would be ridiculously hard.

So, what can you do? Well, one obvious possibility is to run a virtual machine with Linux (or User-Mode Linux, or something similar). Then, just share the source directory with the virtual machine, ssh into the virtual machine, and run pyInstaller from there.

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