如何在.exe中放入.py? [英] How to put .py in .exe?
问题描述
我有Python 3.6,我在.py中做了一个项目,我想将其放入.exe文件中; 我怎样才能做到这一点 ?我尝试了Py2exe,但由于使用了python版本,因此无法正常工作. 感谢您的回答.
I have Python 3.6 and I did a project in .py that I would like to put in an .exe document ; How can I do that ? I tried Py2exe but it did not worked due to my python version. Thanks for your answers.
酒石精
推荐答案
我前几次遇到此问题,经过大量的搜索后,我找到了最适合我的解决方案.
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
,所以我研究了文档并找到了我需要的东西.
Looking the docs it seems to be overcomplicated realize a simple .exe
, so I have studied the documentation and found what I need.
-
打开项目文件夹,并在其中创建一个包含内部内容的
setup.py
文件:
from sys import executable
from cx_Freeze import setup, Executable
setup(name='programName', version='0.1', description='my fancy description')
设置此文件需要一点点研究,有多个设置选项.您可以设置创建简单.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 build
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.
这篇关于如何在.exe中放入.py?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!