can python program packaged with pyinstaller on linux runs on windows?

209 Views Asked by At

My python packaged file runs perfectly on Ubuntu Linux. I open the terminal and type

./[filename]

and the program runs but same thing did not happened on Windows terminal both cmd and powershell. I also tried renaming the file to .exe to make it executable but it also didn't worked for me.

Also, I didn't have python and pyinstaller installed on Windows machine.

1

There are 1 best solutions below

0
On

No, linux-packed pyinstaller programs will not run on windows, you have to get sources of scripts and repack on windows using pyinstaller. Because pysintaller packages executable binary programs and shared libraries inside, which have different format in Windows and Linux.

Content of pyinstaller packed file is a kind of SFX archive in special custom pysintaller's format. I've just looked through pyinstaller's module code and based on received knowledge implemented next simple script to extract all content of pyinstaller's packed file, provide fname in the script:

import os, shutil
from PyInstaller.archive.readers import CArchiveReader

fname = 'z13.exe' # Provide packed filename here
ddir = fname + '_extracted/'

assert os.path.exists(fname), fname + ' not exists!'

if os.path.exists(ddir):
    shutil.rmtree(ddir)
os.makedirs(ddir, exist_ok = True)

r = CArchiveReader(fname)
for fname in r.contents():
    os.makedirs(ddir + os.path.dirname(fname), exist_ok = True)
    data = r.extract(fname)[1]
    with open(ddir + fname, 'wb') as f:
        f.write(data)