python怎么变成exe_Python怎样打包成exe?

分类:Python | 作者:凹凸曼 | 发表于2011/03/01Python怎样打包成exe?已关闭评论

发现PyInstaller 是个不错的东东,解决打包单个exe的问题,使用非常简单,不用编写setup脚本:

进入开发目录,执行命令行(可以做个bat文件):

引用

python d:\pyinstaller-1.3\configure.py

python d:\pyinstaller-1.3\Makespec.py client.py –onefile –windowed –icon=client.ico

python d:\pyinstaller-1.3\build.py client.spec

就这样一个单独的client.exe就产生了,不到3M,是压缩前的三分之一,如果用wxpython大概会有6M多,py2exe压缩的单个exe也差不多这个大小,但py2exe并没有把所有的dll打包。pyinstaller打包比较彻底,就只有一个exe文件。

生成完后同时有个警告文件,内容是:

引用

W: no module named posix (conditional import by os)

W: no module named optik.__all__ (top-level import by optparse)

W: no module named pwd (delayed, conditional import by posixpath)

W: no module named MacOS (top-level import by Tkinter)

W: no module named posix (delayed, conditional import by iu)

W: no module named org (top-level import by copy)

W: no module named _emx_link (conditional import by os)

W: no module named optik.__version__ (top-level import by optparse)

W: __all__ is built strangely at line 0 – __future__ (C:\Python25\lib\__future__.pyc)

W: delayed  __import__ hack detected at line 0 – encodings (C:\Python25\lib\encodings\__init__.pyc)

W: delayed  exec statement detected at line 0 – Tkinter (C:\Python25\lib\lib-tk\Tkinter.pyc)

W: __all__ is built strangely at line 0 – optparse (d:\pyinstaller-1.3\optparse.pyc)

W: delayed  exec statement detected at line 0 – socket (C:\Python25\lib\socket.pyc)

W: delayed  eval hack detected at line 0 – os (C:\Python25\lib\os.pyc)

W: __all__ is built strangely at line 0 – tokenize (C:\Python25\lib\tokenize.pyc)

W: delayed conditional exec statement detected at line 0 – iu (d:\pyinstaller-1.3\iu.pyc)

W: delayed conditional exec statement detected at line 0 – iu (d:\pyinstaller-1.3\iu.pyc)

W: delayed  eval hack detected at line 0 – gettext (C:\Python25\lib\gettext.pyc)

W: delayed  __import__ hack detected at line 0 – optik.option_parser (d:\pyinstaller-1.3\optik\option_parser.pyc)

W: delayed conditional eval hack detected at line 0 – warnings (C:\Python25\lib\warnings.pyc)

W: delayed conditional __import__ hack detected at line 0 – warnings (C:\Python25\lib\warnings.pyc)

W: __all__ is built strangely at line 0 – optik (d:\pyinstaller-1.3\optik\__init__.pyc)

不影响程序使用。

打赏作者

支持:

微信支付

支付宝

您的支持将鼓励我们继续创作!

wxpay.jpg

用 [微信] 扫描二维码打赏

pp1.jpg

用 [支付宝] 扫描二维码打赏

正在跳转到PayPal...

要将Python代码打包exe文件,可以使用以下两种方法: 方法一:使用py2exe 1. 首先,确保你已经安装了py2exe。如果没有安装,可以在命令行中使用以下命令进行安装:pip install py2exe。 2. 创建一个名为setup.py的文件,并在其中添加以下代码: ``` from distutils.core import setup import py2exe setup(console=['your_script.py']) ``` 其中,'your_script.py'是你要打包Python脚本的文件名。 3. 在命令行中,切换到包含setup.py文件的目录,并执行以下命令:python setup.py py2exe。 4. 执行完上述命令后,你将在dist目录中找到一个名为your_script.exe的可执行文件,这就是你打包好的exe文件。 方法二:使用pyinstaller 1. 首先,确保你已经安装了pyinstaller。如果没有安装,可以在命令行中使用以下命令进行安装:pip install pyinstaller。 2. 在命令行中,切换到包含你的Python脚本的目录。 3. 执行以下命令:pyinstaller --onefile your_script.py。 这将在当前目录中生一个名为dist的文件夹,其中包含一个名为your_script.exe的可执行文件。 无论使用哪种方法,最终你都会得到一个打包好的exe文件,可以在没有安装Python解释器的计算机上运行。请注意,打包exe文件可能会增加文件的大小,并且可能会导致一些依赖问题。因此,建议在打包前仔细检查代码和依赖项。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [6种打包Python代码的方法,让你的程序变成exe应用!](https://blog.csdn.net/lojloj/article/details/131760390)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [如何将Python写的代码打包.exe可执行文件](https://blog.csdn.net/weixin_41529012/article/details/116607812)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值