如何将python脚本编译为二进制可执行文件

时间:2021-08-10 20:26:04

I need to convert a Python script to a Windows executable.

我需要将Python脚本转换为Windows可执行文件。

I have Python 2.6 installed to python26.

我在python26上安装了Python 2.6。

I have created one script and kept it in C:\pythonscript. Inside this folder there are two files

我创建了一个脚本并将其保存在C:\ pythonscript中。在这个文件夹里面有两个文件

Setup.py and oldlogs.py (this file need coversion)

Setup.py和oldlogs.py(此文件需要coversion)

setup.py code is

setup.py代码是

from distutils.core import setup
import py2exe

setup(console=['oldlogs.py'])

How can I convert oldlogs.py to an exe file?

如何将oldlogs.py转换为exe文件?

5 个解决方案

#1


47  

Or use PyInstaller as an alternative to py2exe. Here is a good starting point. PyInstaller let's you also create executables for linux and mac...

或者使用PyInstaller作为py2exe的替代品。这是一个很好的起点。 PyInstaller让你也为linux和mac创建可执行文件......

#2


10  

You'll need py2exe. Read a Tutorial.

你需要py2exe。阅读教程。

#3


10  

I've created a presentation that gathers the process from compiling your python sources to package them for every platform (last slide contain links to more detailed instructions)

我创建了一个演示文稿,收集编译python源代码的过程,为每个平台打包它们(最后一张幻灯片包含指向更详细说明的链接)

#4


8  

I recommend PyInstaller, a simple python script can be converted to an exe with the following commands:

我推荐PyInstaller,一个简单的python脚本可以使用以下命令转换为exe:

utils/Makespec.py [--onefile] oldlogs.py

which creates a yourprogram.spec file which is a configuration for building the final exe. Next command builds the exe from the configuration file:

这会创建一个yourprogram.spec文件,这是一个用于构建最终exe的配置。 Next命令从配置文件构建exe:

utils/Build.py oldlogs.spec

More can be found here

更多信息可以在这里找到

#5


6  

For completeness, cx_Freeze is another tool that you can use for this (along with PyInstaller and py2exe, which other answers have already mentioned).

为了完整性,cx_Freeze是您可以使用的另一个工具(与PyInstaller和py2exe一起,其他答案已经提到)。

#1


47  

Or use PyInstaller as an alternative to py2exe. Here is a good starting point. PyInstaller let's you also create executables for linux and mac...

或者使用PyInstaller作为py2exe的替代品。这是一个很好的起点。 PyInstaller让你也为linux和mac创建可执行文件......

#2


10  

You'll need py2exe. Read a Tutorial.

你需要py2exe。阅读教程。

#3


10  

I've created a presentation that gathers the process from compiling your python sources to package them for every platform (last slide contain links to more detailed instructions)

我创建了一个演示文稿,收集编译python源代码的过程,为每个平台打包它们(最后一张幻灯片包含指向更详细说明的链接)

#4


8  

I recommend PyInstaller, a simple python script can be converted to an exe with the following commands:

我推荐PyInstaller,一个简单的python脚本可以使用以下命令转换为exe:

utils/Makespec.py [--onefile] oldlogs.py

which creates a yourprogram.spec file which is a configuration for building the final exe. Next command builds the exe from the configuration file:

这会创建一个yourprogram.spec文件,这是一个用于构建最终exe的配置。 Next命令从配置文件构建exe:

utils/Build.py oldlogs.spec

More can be found here

更多信息可以在这里找到

#5


6  

For completeness, cx_Freeze is another tool that you can use for this (along with PyInstaller and py2exe, which other answers have already mentioned).

为了完整性,cx_Freeze是您可以使用的另一个工具(与PyInstaller和py2exe一起,其他答案已经提到)。