如何将python脚本编译为二进制可执行文件 [英] How to compile python script to binary executable

查看:39
本文介绍了如何将python脚本编译为二进制可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我已将 Python 2.6 安装到 python26.

I have Python 2.6 installed to python26.

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

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

Setup.pyoldlogs.py(此文件需要覆盖)

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

setup.py 代码是

from distutils.core import setup
import py2exe

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

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

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

推荐答案

或者使用 PyInstaller 作为替代方案py2exe.这是一个很好的起点.PyInstaller 还允许您为 linux 和 mac 创建可执行文件...

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

以下是人们可以相当轻松地使用 PyInstaller 解决手头问题的方法:

Here is how one could fairly easily use PyInstaller to solve the issue at hand:

pyinstaller oldlogs.py

来自该工具的文档:

PyInstaller 分析 myscript.py 并:

PyInstaller analyzes myscript.py and:

  • 将 myscript.spec 写入与脚本相同的文件夹中.
  • 如果脚本不存在,则在与脚本相同的文件夹中创建一个文件夹 build.
  • 在构建文件夹中写入一些日志文件和工作文件.
  • 如果脚本不存在,则在与脚本相同的文件夹中创建一个文件夹 dist.
  • 在 dist 文件夹中写入 myscript 可执行文件夹.

在 dist 文件夹中,您可以找到分发给用户的捆绑应用.

In the dist folder you find the bundled app you distribute to your users.

这篇关于如何将python脚本编译为二进制可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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