{"id":4811,"date":"2023-09-12T15:46:30","date_gmt":"2023-09-12T07:46:30","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=4811"},"modified":"2023-09-12T15:46:30","modified_gmt":"2023-09-12T07:46:30","slug":"lightly%e5%a6%82%e4%bd%95%e7%94%9f%e6%88%90exe%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/4811\/","title":{"rendered":"lightly\u5982\u4f55\u751f\u6210exe\uff1f"},"content":{"rendered":"

Lightly\u662f\u4e00\u4e2a\u57fa\u4e8ePython\u7684\u8f7b\u91cf\u7ea7Web\u6846\u67b6\uff0c\u5b83\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u4eba\u5458\u5feb\u901f\u6784\u5efaWeb\u5e94\u7528<\/p>\n

<\/figure>\n<\/p>\n

\u7a0b\u5e8f\u3002\u5728\u5f00\u53d1\u5b8c\u6210\u540e\uff0c\u901a\u5e38\u9700\u8981\u5c06\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528PyInstaller\u5c06Lightly\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210exe\u6587\u4ef6\u3002<\/p>\n

PyInstaller\u662f\u4e00\u4e2a\u7528\u4e8e\u5c06Python\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u5355\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5de5\u5177\u3002\u5b83\u53ef\u4ee5\u81ea\u52a8\u68c0\u6d4b\u5e94\u7528\u7a0b\u5e8f\u6240\u4f9d\u8d56\u7684\u5e93\u548c\u8d44\u6e90\u6587\u4ef6\uff0c\u5e76\u5c06\u5b83\u4eec\u6253\u5305\u5230\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\u4e2d\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528PyInstaller\u5c06Lightly\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210exe\u6587\u4ef6\u7684\u6b65\u9aa4\uff1a<\/p>\n

\u6b65\u9aa41\uff1a\u5b89\u88c5PyInstaller<\/p>\n

\u5728\u4f7f\u7528PyInstaller\u4e4b\u524d\uff0c\u9700\u8981\u5148\u5b89\u88c5\u5b83\u3002\u53ef\u4ee5\u4f7f\u7528pip\u547d\u4ee4\u5728\u547d\u4ee4\u884c\u4e2d\u5b89\u88c5PyInstaller\uff1a<\/p>\n

“`<\/p>\n

pip install pyinstaller<\/p>\n

“`<\/p>\n

\u6b65\u9aa42\uff1a\u521b\u5efaspec\u6587\u4ef6<\/p>\n

\u4f7f\u7528PyInstaller\u6253\u5305\u5e94\u7528\u7a0b\u5e8f\u7684\u7b2c\u4e00\u6b65\u662f\u521b\u5efaspec\u6587\u4ef6\u3002spec\u6587\u4ef6\u5305\u542b\u6709\u5173\u5e94\u7528\u7a0b\u5e8f\u7684\u4fe1\u606f\uff0c\u4f8b\u5982\u5e94\u7528\u7a0b\u5e8f\u7684\u540d\u79f0\u3001\u7248\u672c\u3001\u56fe\u6807\u6587\u4ef6\u7b49\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efaspec\u6587\u4ef6\uff1a<\/p>\n

“`<\/p>\n

pyinstaller –name=your_app_name –onefile your_app.py<\/p>\n

“`<\/p>\n

\u5176\u4e2d\uff0c`–name`\u53c2\u6570\u6307\u5b9a\u5e94\u7528\u7a0b\u5e8f\u7684\u540d\u79f0\uff0c`–onefile`\u53c2\u6570\u6307\u5b9a\u5c06\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u5355\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002`your_app.py`\u662f\u5e94\u7528\u7a0b\u5e8f\u7684\u5165\u53e3\u6587\u4ef6\u3002<\/p>\n

\u6267\u884c\u4ee5\u4e0a\u547d\u4ee4\u540e\uff0cPyInstaller\u5c06\u5728\u5f53\u524d\u76ee\u5f55\u4e2d\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a`your_app_name.spec`\u7684spec\u6587\u4ef6\u3002<\/p>\n

\u6b65\u9aa43\uff1a\u7f16\u8f91spec\u6587\u4ef6<\/p>\n

\u5728spec\u6587\u4ef6\u4e2d\uff0c\u53ef\u4ee5\u7f16\u8f91\u5e94\u7528\u7a0b\u5e8f\u7684\u5404\u79cd\u5c5e\u6027\uff0c\u4f8b\u5982\u5e94\u7528\u7a0b\u5e8f\u7684\u540d\u79f0\u3001\u7248\u672c\u3001\u56fe\u6807\u6587\u4ef6\u7b49\u3002\u53ef\u4ee5\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\u6253\u5f00spec\u6587\u4ef6\u8fdb\u884c\u7f16\u8f91\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2aspec\u6587\u4ef6\u7684\u793a\u4f8b\uff1a<\/p>\n

“`<\/p>\n

# your_app_name.spec<\/p>\n

# -*- mode: python ; coding: utf-8 -*-<\/p>\n

block_cipher = None<\/p>\n

a = Analysis([‘your_app.py’],<\/p>\n

pathex=[‘\/path\/to\/your\/app’],<\/p>\n

binaries=[],<\/p>\n

datas=[(‘\/path\/to\/your\/templates’, ‘templates’)],<\/p>\n

hiddenimports=[‘your_app_module’],<\/p>\n

hookspath=[],<\/p>\n

runtime_hooks=[],<\/p>\n

excludes=[],<\/p>\n

win_no_prefer_redirects=False,<\/p>\n

win_private_assemblies=False,<\/p>\n

cipher=block_cipher,<\/p>\n

noarchive=False)<\/p>\n

pyz = PYZ(a.pure, a.zipped_data,<\/p>\n

cipher=block_cipher)<\/p>\n

exe = EXE(pyz,<\/p>\n

a.scripts,<\/p>\n

a.binaries,<\/p>\n

a.zipfiles,<\/p>\n

window\u5e94\u7528<\/a><\/p>\n

a.datas,<\/p>\n

[],<\/p>\n

name=’your_app_name’,<\/p>\n

debug=False,<\/p>\n

bootloader_ignore_signals=False,<\/p>\n

strip=False,<\/p>\n

upx=True,<\/p>\n

upx_exclude=\u7f51\u9875\u80fd\u4e0d\u80fd\u6253\u5305\u6210exe\u6587\u4ef6<\/a>[],<\/p>\n

runtime_tmpdir=None,<\/p>\n

console=True )<\/p>\n

“`<\/p>\n

\u5728spec\u6587\u4ef6\u4e2d\uff0c\u53ef\u4ee5\u7f16\u8f91\u4ee5\u4e0b\u5c5e\u6027\uff1a<\/p>\n

– `Analysis`\u5bf9\u8c61\u7684`pathex`\u5c5e\u6027\uff1a\u6307\u5b9a\u5e94\u7528\u7a0b\u5e8f\u7684\u8def\u5f84\u3002<\/p>\n

– `Analysis`\u5bf9\u8c61\u7684`binaries`\u5c5e\u6027\uff1a\u6307\u5b9a\u5e94\u7528\u7a0b\u5e8f\u4f9d\u8d56\u7684\u4e8c\u8fdb\u5236\u6587\u4ef6\u3002<\/p>\n

– `Analysis<\/p>\n","protected":false},"excerpt":{"rendered":"

Lightly\u662f\u4e00\u4e2a\u57fa\u4e8ePython\u7684\u8f7b\u91cf\u7ea7Web\u6846\u67b6\uff0c\u5b83\u53ef\u4ee5\u5e2e\u52a9\u5f00\u53d1\u4eba\u5458\u5feb\u901f\u6784\u5efaWeb\u5e94\u7528\u7a0b\u5e8f\u3002\u5728\u5f00\u53d1\u5b8c\u6210\u540e\uff0c\u901a\u5e38\u9700\u8981\u5c06\u5e94\u7528\u7a0b\u5e8f\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528PyInstaller\u5c06Ligh<\/p>\n","protected":false},"author":7,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[9138,9139,12,16,25],"topic":[],"class_list":["post-4811","post","type-post","status-publish","format-standard","hentry","category-exekf","tag-flashexe","tag-exe","tag-12","tag-16","tag-25"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/4811","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=4811"}],"version-history":[{"count":0,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/4811\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=4811"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=4811"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=4811"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=4811"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}