py2exe 的跨平台替代品 [英] Cross-platform alternative to py2exe

查看:28
本文介绍了py2exe 的跨平台替代品的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

py2exe 很棒,每当我想打包 Python 程序在 Windows 系统上运行时都会使用它.

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

我的问题是,是否有一个等效的工具可以用来在 Windows 上打包程序,然后我可以在 Linux 上运行?

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?

推荐答案

好的,我已经完成了.这有点笨拙,但它非常适合我的用例.

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

它的要点是使用 ModuleFinder 查找所有导入的模块,过滤掉任何系统模块,编译并压缩它们.

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)

这篇关于py2exe 的跨平台替代品的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆