如何将python .py文件转换为可执行文件以供跨平台使用? [英] How to convert python .py file into an executable file for use cross platform?

查看:101
本文介绍了如何将python .py文件转换为可执行文件以供跨平台使用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经搜索了一段时间,试图找到答案,但是由于我缺乏编程经验,所以我对文档的了解不多,也没有足够的信心进行过多的实验。

I've been searching through SO for a while now trying to come up with an answer to this but due to my inexperience with programming I don't understand much of the documentation, nor am I confident enough to experiment too much.

有人能用稍微简单的术语来描述我将如何使用Py2exe,PyInstaller,cx_freeze等程序吗?我只希望其他人(主要是朋友)能够运行我的程序(仅简单文本)而不必自己下载python。如果有更简便的方法,我也很高兴知道这一点。

Would anyone be able to describe in slightly simpler terms how I would use programs like Py2exe, PyInstaller, cx_freeze etc.? I just want a way for others (mainly friends) to be able to run my (simple, text only) program without having to download python themselves. If there is an easier way to do this I'd appreciate knowing that too.

运行Vista 32位,python 2.7

Running Vista 32bit, python 2.7

推荐答案

有两个截然不同的地方冻结python脚本以创建可执行文件的方法:

There are two distinct ways of freezing python scripts to create executables:


  1. 将解释器和* .pyc文件打包到一个exe文件容器中。诸如 PyInstaller Py2exe cx_freeze

  2. 从Python源创建本地代码,通常使用将Python源转换为C或C ++代码的中间步骤。这可以通过 Shed-skin Nuitka 。这种方法的问题在于,此类工具并不总是支持Python的所有功能(例如,它们可能有一些键入限制等等)

  1. Packing the interpreter and *.pyc files into one exe file-container. Such an approach is used by tools like PyInstaller, Py2exe, cx_freeze.
  2. Creating native code from Python source, usually using a middle step of converting Python-source to C or C++ code. This is done by such tools as Shed-skin and Nuitka. The problem of this aproach is that such tools do not always support all the functionality of Python (e.g. they can have some typing limitations and so on)

您必须首先阅读文档。这样的工具不仅是即推即用风格的工具,它们通常还具有一些必须实现的配置(这可能是所有构建系统的问题,并且随着项目的发展,挂钩的配置和数量也随之增长)。

The point where you have to start is reading the documentation. Such tools are not just push-and-run style tools, they usually have some configuration that must be implemented (that's the problem of possibly all build systems, and as the project grows, the configuration and number of hooks also grows).

您可以从 Py2exe教程和 hello-world了解如何完成编译。据我所知,这是达成目标的最简单方法。

You can start with Py2exe tutorial and 'hello-world' to get acquainted with that how compilation is done. As far as I know it's a simplest way to get your goal.

最后,您不能创建跨平台的本机可执行文件 >,因为它们的文件格式很大程度上取决于操作系统和硬件

And the last thing, you can't create cross-platform native executables as their file formats are strongly operating system and hardware dependent.

这篇关于如何将python .py文件转换为可执行文件以供跨平台使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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