How to compile python script to binary executable

2019-01-03 08:13发布

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

I have Python 2.6 installed to python26.

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

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

setup.py code is

from distutils.core import setup
import py2exe

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

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

5条回答
你好瞎i
2楼-- · 2019-01-03 08:36

You'll need py2exe. Read a Tutorial.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-01-03 08:37

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...

查看更多
倾城 Initia
4楼-- · 2019-01-03 08:44

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

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:

utils/Build.py oldlogs.spec

More can be found here

查看更多
相关推荐>>
5楼-- · 2019-01-03 08:56

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

查看更多
闹够了就滚
6楼-- · 2019-01-03 09:02

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)

查看更多
登录 后发表回答