Cross-platform alternative to py2exe [closed]

久未见 提交于 2019-12-17 23:18:09

问题


py2exe is great, and I use it whenever I want to package up a python program to run on a Windows system.

My question is, is there an equivalent tool that I can use to package up the program on Windows, but that I can then run on Linux?


回答1:


here is also PyInstaller that supports Linux, MacOS and Windows - I have not used it (yet) so I don't know if you can package stuff on windows for linux, but glancing over the manual it seems to be possible.

EDIT: The FAQ states explicitly that you can not create a windows package from linux and no mac os package from linux neither - there is nothing about creating a linux package from the other two sources, but it might not work.

EDIT2: After googling a bit I found cx_freeze which might also be worth a look.




回答2:


I really doubt that you can do something like that at all.

What you could do is just configure yourself 3 build VMs one for Windows, one for MacOS and one for Linux that have everyhing you need to run your program.

Then use either a combination of py2exe/py2app/pyinstaller to generate a distribution for each of the platforms. You will have 3 different pacakges but each one of them will be nicely packed and with no need to install anything else on the client machines.




回答3:


Ok, I've done this. It's a little hacky, but it works very well for my use case.

The gist of it is to use ModuleFinder to find all imported modules, filter out any system ones, compile them and zip them up.

Unfortunately my code for this is littered with additional complications that don't have any relevance to this question, so I can't paste a working program, just some snippets:

zipfile = ZipFile(os.path.join(dest_dir, zip_name), 'w', ZIP_DEFLATED)
sys.path.insert(0, '.')
finder = ModuleFinder()
finder.run_script(source_name)

for name, mod in finder.modules.iteritems():
    filename = mod.__file__
    if filename is None:
        continue
    if "python" in filename.lower():
        continue

    subprocess.call('"%s" -OO -m py_compile "%s"' % (python_exe, filename))

    zipfile.write(filename, dest_path)


来源:https://stackoverflow.com/questions/9035424/cross-platform-alternative-to-py2exe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!