为Python 2.7创建可执行文件 [英] Creating Executable File For Python 2.7

查看:74
本文介绍了为Python 2.7创建可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从python文件制作可执行文件,而该python文件是为python 2.7编写的.

I want to make an executable file from a python file the python file is written for Python 2.7.

我尝试了 pyinstaller ,但安装时出现错误.我猜它不再支持Python 2.7.

I tried pyinstaller but it gives me an error when installing. I'm guessing it does not have support for Python 2.7 anymore.

是否有与Python 2.7兼容的 pyinstaller 替代品?

Are there any alternatives for pyinstaller that work with Python 2.7?

我尝试安装 cx_Freeze 版本5.1.1,但它给了我以下错误:

I tried installing cx_Freeze version 5.1.1 but it gives me the following error:

Cleaning up...
Command C:\Python27\python.exe -c "import setuptools, tokenize;__file__='c:\\users\\win-10\\appdata\\local\\temp\\pip_build_win-10\\cx-Freeze\\setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record c:\users\win-10\appdata\local\temp\pip-cn4sd_-record\install-record.txt --single-version-externally-managed --compile failed with error code 1 in c:\users\win-10\appdata\local\temp\pip_build_win-10\cx-Freeze
Storing debug log for failure in C:\Users\win-10\pip\pip.log

当我从车轮安装时

cx_Freeze-5.1.1-cp27-cp27m-win_amd64.whl is not a supported wheel on this platform.
Storing debug log for failure in C:\Users\win-10\pip\pip.log

setup.py

from sys import executable
from cx_Freeze import setup, Executable

setup(name='server', version='0.1', description='reverse shell server')

推荐答案

我前几次遇到此问题,经过大量的搜索后,我找到了最适合我的解决方案.

I faced this problem some times ago, after a lot of googling I found the best solution for me.

  • Py2Exe :很旧,PyPi的最新版本是2014年10月21日.
  • pyInstaller :是一个不错的工具,但是有一些问题,我们稍后会看到.
  • 自动py-exe :使用pyInstaller构建 .exe ,因此也遇到了同样的问题,但是具有不错的GUI且使用起来很直观.
  • cx_Freeze :我认为最好的解决方案是因为在我的情况下唯一可行的方法,也是从python建议
  • Py2Exe: Which is old, the last release on PyPi is on 21 October 2014.
  • pyInstaller: Is a nice tool, but with some problem that we will see later.
  • auto-py-to-exe: Use pyInstaller to build the .exe, so suffer the same problem, but has a nice GUI and is intuitive to use.
  • cx_Freeze: I think the best solution, because it was the only one that works in my case, it is also recommended from python

这一次,我每次都在google和StackOverflow上寻找最佳解决方案,每次我发现它过时或没有得到很好的解释/记录,因此我研究了官方文档.

During this time I looked on google and StackOverflow for the best solution, each time that I found something it was out-dated or not well explained/documented, so I studied the official docs.

第一次尝试安装py2exe时,这似乎是最好的选择,也推荐从python进行尝试,因此,请尝试一下.在安装过程中一切正常,所以我决定遵循教程并获取我的 .exe .

As first try I installed py2exe it seems the best option, also recommended from python, so, give it a try. All goes fine during the installation process, so I decide to follow the tutorial and get my .exe.

在本教程的第3步中,运行安装程序时收到一个错误,在Google上查看时,我发现.

During the step 3 of the tutorial, running setup I received an error, looking on google I found this.

我放弃了py2exe.

I gave up with py2exe.

我已经安装了auto-py-to-exe,并且一切正常,程序打开没有问题,所以我创建了我的 .exe 文件,该文件可以正常工作!

I have installed auto-py-to-exe and all went good, the program open without problems so I create my .exe file, that works!

唯一的问题是,该程序只能在我的笔记本电脑上运行,并且在我尝试执行防病毒的所有其他计算机上都可以删除它.

The only problem was that, the program works only on my laptop, on all the other machine where I try to execute the antivirus delete it.

在Google上,我找到了 github存储库,在其中找到了一个<像我的一样,href ="https://github.com/brentvollebregt/auto-py-to-exe/issues/16" rel ="nofollow noreferrer"> issue ,阅读它我知道问题出在pyInstaller.

Looking on google I found the github repository where I found one issue like the mine, reading it I understand that the problem is pyInstaller.

pyInstaller存储库中,我找到了一个

Looking on the pyInstaller repository I found one issue where one contributors tells to contact the antivirus vendo, so I gave up again.

查看 docs 似乎过于复杂,实现了一个简单的方法 .exe ,因此我研究了文档并找到了我所需要的.如果需要对Python 2.x的支持,则应改用cx_Freeze版本5.1.x,只需运行 pip install cx-Freeze == 5.1.1

Looking the docs it seems to be overcomplicated realize a simple .exe, so I have studied the documentation and found what I need. If you need support for Python 2.x, cx_Freeze version 5.1.x should be used instead, to do it just run pip install cx-Freeze==5.1.1

  • 打开项目文件夹,并在其中创建一个 setup.py 文件,其中包含以下内容:

  • Open you project folder and create inside it a setup.py file with inside:

import sys
from cx_Freeze import setup, Executable

setup(  name = "myProgram",
        version = "0.1",
        description = "",
        executables = [Executable("myProgram.py")])

设置此文件需要一点点研究,有多个设置选项.您可以设置创建简单的 .exe 的选项,也可以创建Windows/mac/linux安装程序.

Setting up this file require a little bit of study, there are multiple options to set. You can set the option to create a simple .exe or also the create a windows/mac/linux installer.

准备好文件后,使用所需的选项,只需在 setup.py 文件所在的目录中打开shell/terminal/cmd并执行:<代码> python setup.py构建

Once you have your file ready, with the options that you need, just open a shell/terminal/cmd in the directory where the setup.py file is located and execute: python setup.py build

现在在项目文件夹中,您会看到一个文件夹,您可以在其中找到 .exe 文件.

Now in your project folder you will see a folder where inside you can find your .exe file.

这篇关于为Python 2.7创建可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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