{"id":1161373,"date":"2025-01-13T19:15:44","date_gmt":"2025-01-13T11:15:44","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1161373.html"},"modified":"2025-01-13T19:15:47","modified_gmt":"2025-01-13T11:15:47","slug":"python%e7%a8%8b%e5%ba%8f%e5%a6%82%e4%bd%95%e5%b0%81%e8%a3%85%e6%88%90exe","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1161373.html","title":{"rendered":"python\u7a0b\u5e8f\u5982\u4f55\u5c01\u88c5\u6210exe"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25202645\/3f0c31b6-c549-457c-9df8-94c0d425fdf4.webp\" alt=\"python\u7a0b\u5e8f\u5982\u4f55\u5c01\u88c5\u6210exe\" \/><\/p>\n<p><p> <strong>\u5c06Python\u7a0b\u5e8f\u5c01\u88c5\u6210exe\u6587\u4ef6\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5e38\u7528\u7684\u5de5\u5177\u5305\u62ecPyInstaller\u3001cx_Freeze\u3001py2exe\u3002PyInstaller\u3001cx_Freeze\u3001py2exe<\/strong>\u662f\u5c06Python\u811a\u672c\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5e38\u7528\u5de5\u5177\uff0c\u5176\u4e2d<strong>PyInstaller<\/strong>\u662f\u6700\u4e3a\u6d41\u884c\u548c\u6613\u7528\u7684\u4e00\u79cd\uff0c\u5b83\u80fd\u591f\u81ea\u52a8\u5206\u6790\u548c\u6536\u96c6\u4f9d\u8d56\u9879\uff0c\u751f\u6210\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u4f7f\u7528PyInstaller\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5b89\u88c5PyInstaller<\/h3>\n<\/p>\n<p><h4>1.\u4f7f\u7528pip\u5b89\u88c5PyInstaller<\/h4>\n<\/p>\n<p><p>PyInstaller\u7684\u5b89\u88c5\u975e\u5e38\u7b80\u5355\uff0c\u53ef\u4ee5\u76f4\u63a5\u901a\u8fc7pip\u8fdb\u884c\u5b89\u88c5\u3002\u6253\u5f00\u547d\u4ee4\u884c\u7a97\u53e3\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pyinstaller<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u4e0b\u8f7d\u5e76\u5b89\u88c5PyInstaller\u7684\u6700\u65b0\u7248\u672c\u3002<\/p>\n<\/p>\n<p><h4>2.\u9a8c\u8bc1\u5b89\u88c5<\/h4>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u5728\u547d\u4ee4\u884c\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u9a8c\u8bc1\u662f\u5426\u5b89\u88c5\u6210\u529f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u663e\u793aPyInstaller\u7684\u7248\u672c\u53f7\uff0c\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528PyInstaller\u6253\u5305Python\u811a\u672c<\/h3>\n<\/p>\n<p><h4>1.\u521b\u5efa\u6d4b\u8bd5\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u6211\u4eec\u9700\u8981\u4e00\u4e2aPython\u811a\u672c\u6765\u8fdb\u884c\u6253\u5305\u6d4b\u8bd5\u3002\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>test.py<\/code>\u7684\u6587\u4ef6\uff0c\u5e76\u7f16\u5199\u4e00\u4e9b\u7b80\u5355\u7684\u4ee3\u7801\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(&quot;Hello, World!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2.\u6253\u5305Python\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u5bfc\u822a\u5230\u5305\u542b<code>test.py<\/code>\u7684\u76ee\u5f55\uff0c\u7136\u540e\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile test.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p><code>--onefile<\/code>\u9009\u9879\u8868\u793a\u5c06\u6240\u6709\u5185\u5bb9\u6253\u5305\u6210\u4e00\u4e2a\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u6267\u884c\u4e0a\u8ff0\u547d\u4ee4\u540e\uff0cPyInstaller\u5c06\u81ea\u52a8\u751f\u6210\u4e00\u4e2a\u540d\u4e3a<code>dist<\/code>\u7684\u76ee\u5f55\uff0c\u91cc\u9762\u5305\u542b\u751f\u6210\u7684exe\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>3.\u8fd0\u884c\u751f\u6210\u7684exe\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u5728<code>dist<\/code>\u76ee\u5f55\u4e0b\uff0c\u627e\u5230<code>test.exe<\/code>\u6587\u4ef6\uff0c\u53cc\u51fb\u8fd0\u884c\u5b83\u3002\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u4f60\u5c06\u770b\u5230\u8f93\u51fa<code>Hello, World!<\/code>\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001PyInstaller\u7684\u9ad8\u7ea7\u9009\u9879<\/h3>\n<\/p>\n<p><h4>1.\u6307\u5b9a\u56fe\u6807<\/h4>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u4f7f\u7528<code>--icon<\/code>\u9009\u9879\u4e3a\u751f\u6210\u7684exe\u6587\u4ef6\u6307\u5b9a\u4e00\u4e2a\u56fe\u6807\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile --icon=myicon.ico test.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2.\u9690\u85cf\u63a7\u5236\u53f0\u7a97\u53e3<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u662f\u56fe\u5f62\u754c\u9762\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u4f7f\u7528<code>--noconsole<\/code>\u9009\u9879\u9690\u85cf\u63a7\u5236\u53f0\u7a97\u53e3\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile --noconsole test.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3.\u6dfb\u52a0\u6570\u636e\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u6709\u65f6\u4f60\u7684\u7a0b\u5e8f\u53ef\u80fd\u9700\u8981\u4e00\u4e9b\u6570\u636e\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>--add-data<\/code>\u9009\u9879\u6dfb\u52a0\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile --add-data &quot;data.txt;.&quot; test.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u628a<code>data.txt<\/code>\u6587\u4ef6\u6253\u5305\u5230exe\u6587\u4ef6\u4e2d\uff0c\u5e76\u5728\u8fd0\u884c\u65f6\u5c06\u5176\u63d0\u53d6\u5230\u5f53\u524d\u76ee\u5f55\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528PyInstaller\u6253\u5305\u5177\u6709\u4f9d\u8d56\u9879\u7684\u9879\u76ee<\/h3>\n<\/p>\n<p><h4>1.\u5b89\u88c5\u4f9d\u8d56\u9879<\/h4>\n<\/p>\n<p><p>\u5bf9\u4e8e\u4e00\u4e2a\u590d\u6742\u7684\u9879\u76ee\uff0c\u53ef\u80fd\u4f1a\u6709\u591a\u4e2a\u4f9d\u8d56\u9879\u3002\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86\u6240\u6709\u4f9d\u8d56\u9879\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip<\/code>\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install -r requirements.txt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2.\u521b\u5efaspec\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>PyInstaller\u4f7f\u7528spec\u6587\u4ef6\u6765\u5b9a\u4e49\u6253\u5305\u7684\u8be6\u7ec6\u914d\u7f6e\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u751f\u6210\u9ed8\u8ba4\u7684spec\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile --noconfirm --name=MyApp m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u751f\u6210\u4e00\u4e2a\u540d\u4e3a<code>MyApp.spec<\/code>\u7684\u6587\u4ef6\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u9700\u8981\u8fdb\u884c\u7f16\u8f91\u3002<\/p>\n<\/p>\n<p><h4>3.\u7f16\u8f91spec\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u6253\u5f00\u751f\u6210\u7684spec\u6587\u4ef6\uff0c\u53ef\u4ee5\u770b\u5230\u7c7b\u4f3c\u4e0b\u9762\u7684\u5185\u5bb9\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\"># -*- mode: python ; coding: utf-8 -*-<\/p>\n<p>block_cipher = None<\/p>\n<p>a = Analysis([&#39;main.py&#39;],<\/p>\n<p>             pathex=[],<\/p>\n<p>             binaries=[],<\/p>\n<p>             datas=[],<\/p>\n<p>             hiddenimports=[],<\/p>\n<p>             hookspath=[],<\/p>\n<p>             runtime_hooks=[],<\/p>\n<p>             excludes=[],<\/p>\n<p>             win_no_prefer_redirects=False,<\/p>\n<p>             win_private_assemblies=False,<\/p>\n<p>             cipher=block_cipher,<\/p>\n<p>             noarchive=False)<\/p>\n<p>pyz = PYZ(a.pure, a.zipped_data,<\/p>\n<p>             cipher=block_cipher)<\/p>\n<p>exe = EXE(pyz,<\/p>\n<p>          a.scripts,<\/p>\n<p>          [],<\/p>\n<p>          exclude_binaries=True,<\/p>\n<p>          name=&#39;MyApp&#39;,<\/p>\n<p>          debug=False,<\/p>\n<p>          bootloader_ignore_signals=False,<\/p>\n<p>          strip=False,<\/p>\n<p>          upx=True,<\/p>\n<p>          upx_exclude=[],<\/p>\n<p>          runtime_tmpdir=None,<\/p>\n<p>          console=True )<\/p>\n<p>coll = COLLECT(exe,<\/p>\n<p>               a.binaries,<\/p>\n<p>               a.zipfiles,<\/p>\n<p>               a.datas,<\/p>\n<p>               strip=False,<\/p>\n<p>               upx=True,<\/p>\n<p>               upx_exclude=[],<\/p>\n<p>               name=&#39;MyApp&#39;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4f60\u53ef\u4ee5\u5728<code>Analysis<\/code>\u90e8\u5206\u4e2d\u6dfb\u52a0\u4f9d\u8d56\u9879\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">a = Analysis([&#39;main.py&#39;],<\/p>\n<p>             pathex=[&#39;.\/path_to_module&#39;],<\/p>\n<p>             binaries=[],<\/p>\n<p>             datas=[(&#39;data.txt&#39;, &#39;.&#39;)],<\/p>\n<p>             hiddenimports=[&#39;some_hidden_module&#39;],<\/p>\n<p>             hookspath=[],<\/p>\n<p>             runtime_hooks=[],<\/p>\n<p>             excludes=[],<\/p>\n<p>             win_no_prefer_redirects=False,<\/p>\n<p>             win_private_assemblies=False,<\/p>\n<p>             cipher=block_cipher,<\/p>\n<p>             noarchive=False)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4.\u751f\u6210exe\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u7f16\u8f91\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u751f\u6210exe\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller MyApp.spec<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u6839\u636espec\u6587\u4ef6\u4e2d\u7684\u914d\u7f6e\u751f\u6210exe\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001cx_Freeze\u7684\u4f7f\u7528<\/h3>\n<\/p>\n<p><h4>1.\u5b89\u88c5cx_Freeze<\/h4>\n<\/p>\n<p><p>cx_Freeze\u4e5f\u662f\u4e00\u4e2a\u5e38\u7528\u7684\u6253\u5305\u5de5\u5177\uff0c\u5b89\u88c5\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install cx_Freeze<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2.\u521b\u5efasetup\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>setup.py<\/code>\u7684\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from cx_Freeze import setup, Executable<\/p>\n<p>setup(<\/p>\n<p>    name = &quot;MyApp&quot;,<\/p>\n<p>    version = &quot;1.0&quot;,<\/p>\n<p>    description = &quot;My Application&quot;,<\/p>\n<p>    executables = [Executable(&quot;main.py&quot;)]<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3.\u8fd0\u884csetup\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python setup.py build<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u5728<code>build<\/code>\u76ee\u5f55\u4e0b\u751f\u6210exe\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001py2exe\u7684\u4f7f\u7528<\/h3>\n<\/p>\n<p><h4>1.\u5b89\u88c5py2exe<\/h4>\n<\/p>\n<p><p>py2exe\u662f\u53e6\u4e00\u4e2a\u5e38\u7528\u7684\u6253\u5305\u5de5\u5177\uff0c\u5b89\u88c5\u65b9\u6cd5\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install py2exe<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2.\u521b\u5efasetup\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>setup.py<\/code>\u7684\u6587\u4ef6\uff0c\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from distutils.core import setup<\/p>\n<p>import py2exe<\/p>\n<p>setup(<\/p>\n<p>    console=[&#39;main.py&#39;]<\/p>\n<p>)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3.\u8fd0\u884csetup\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python setup.py py2exe<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u5728<code>dist<\/code>\u76ee\u5f55\u4e0b\u751f\u6210exe\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u5e38\u89c1\u95ee\u9898\u53ca\u89e3\u51b3\u65b9\u6848<\/h3>\n<\/p>\n<p><h4>1.\u7f3a\u5c11\u4f9d\u8d56\u9879<\/h4>\n<\/p>\n<p><p>\u5728\u6253\u5305\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u4f9d\u8d56\u9879\u6ca1\u6709\u6b63\u786e\u6253\u5305\u7684\u95ee\u9898\u3002\u4f60\u53ef\u4ee5\u5728spec\u6587\u4ef6\u4e2d\u624b\u52a8\u6dfb\u52a0\u8fd9\u4e9b\u4f9d\u8d56\u9879\u5230<code>hiddenimports<\/code>\u4e2d\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">hiddenimports=[&#39;some_hidden_module&#39;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2.\u8def\u5f84\u95ee\u9898<\/h4>\n<\/p>\n<p><p>\u6253\u5305\u540e\u7684exe\u6587\u4ef6\u8fd0\u884c\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u8def\u5f84\u95ee\u9898\u3002\u786e\u4fdd\u5728spec\u6587\u4ef6\u4e2d\u6b63\u786e\u8bbe\u7f6e<code>pathex<\/code>\u548c<code>datas<\/code>\u9009\u9879\u3002<\/p>\n<\/p>\n<p><h4>3.\u56fe\u6807\u663e\u793a\u95ee\u9898<\/h4>\n<\/p>\n<p><p>\u6709\u65f6exe\u6587\u4ef6\u7684\u56fe\u6807\u53ef\u80fd\u65e0\u6cd5\u6b63\u786e\u663e\u793a\u3002\u786e\u4fdd\u56fe\u6807\u6587\u4ef6\u7684\u8def\u5f84\u6b63\u786e\uff0c\u5e76\u4e14\u4f7f\u7528\u7684\u662fico\u683c\u5f0f\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5c06Python\u7a0b\u5e8f\u5c01\u88c5\u6210exe\u6587\u4ef6\u7684\u8fc7\u7a0b\u6d89\u53ca\u591a\u4e2a\u6b65\u9aa4\u548c\u5de5\u5177\u9009\u62e9\u3002<strong>PyInstaller\u3001cx_Freeze\u3001py2exe<\/strong>\u662f\u5e38\u7528\u7684\u6253\u5305\u5de5\u5177\uff0c\u5176\u4e2d<strong>PyInstaller<\/strong>\u6700\u4e3a\u6d41\u884c\u548c\u6613\u7528\u3002\u901a\u8fc7\u6b63\u786e\u5b89\u88c5\u548c\u914d\u7f6e\u8fd9\u4e9b\u5de5\u5177\uff0c\u53ef\u4ee5\u8f7b\u677e\u5730\u5c06Python\u811a\u672c\u6253\u5305\u6210\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u80fd\u591f\u5e2e\u52a9\u4f60\u987a\u5229\u5b8c\u6210Python\u7a0b\u5e8f\u7684\u6253\u5305\u5de5\u4f5c\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5c06Python\u7a0b\u5e8f\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\uff1f<\/strong><br \/>\u8981\u5c06Python\u7a0b\u5e8f\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\uff08.exe\uff09\uff0c\u53ef\u4ee5\u4f7f\u7528\u50cfPyInstaller\u3001cx_Freeze\u6216py2exe\u7b49\u5de5\u5177\u3002PyInstaller\u662f\u6700\u5e38\u7528\u7684\u9009\u62e9\uff0c\u5b83\u53ef\u4ee5\u5c06Python\u811a\u672c\u53ca\u5176\u4f9d\u8d56\u9879\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u72ec\u7acb\u8fd0\u884c\u7684exe\u6587\u4ef6\u3002\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u53ea\u9700\u8fd0\u884c<code>pyinstaller your_script.py<\/code>\u5373\u53ef\u751f\u6210exe\u6587\u4ef6\uff0c\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u8f93\u51fa\u6587\u4ef6\u5c06\u4f4d\u4e8e<code>dist<\/code>\u6587\u4ef6\u5939\u4e2d\u3002<\/p>\n<p><strong>\u8f6c\u6362\u4e3aexe\u540e\u7a0b\u5e8f\u7684\u8fd0\u884c\u73af\u5883\u4f1a\u6709\u4ec0\u4e48\u53d8\u5316\uff1f<\/strong><br \/>\u4e00\u65e6Python\u7a0b\u5e8f\u88ab\u6253\u5305\u4e3aexe\u6587\u4ef6\uff0c\u5b83\u5c06\u4e0d\u518d\u4f9d\u8d56\u4e8ePython\u89e3\u91ca\u5668\u7684\u5b89\u88c5\u3002\u7528\u6237\u53ef\u4ee5\u5728\u6ca1\u6709Python\u73af\u5883\u7684\u8ba1\u7b97\u673a\u4e0a\u76f4\u63a5\u8fd0\u884c\u8fd9\u4e2aexe\u6587\u4ef6\u3002\u8fd9\u79cd\u72ec\u7acb\u6027\u4f7f\u5f97\u7a0b\u5e8f\u66f4\u6613\u4e8e\u5206\u53d1\u548c\u4f7f\u7528\uff0c\u4f46\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u6253\u5305\u540e\u7684\u6587\u4ef6\u901a\u5e38\u4f1a\u6bd4\u539f\u59cbPython\u811a\u672c\u5927\uff0c\u56e0\u4e3a\u5b83\u5305\u542b\u4e86\u6240\u6709\u7684\u4f9d\u8d56\u9879\u548c\u89e3\u91ca\u5668\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406Python\u7a0b\u5e8f\u4e2d\u7684\u5916\u90e8\u8d44\u6e90\uff1f<\/strong><br \/>\u5728\u5c06Python\u7a0b\u5e8f\u6253\u5305\u6210exe\u6587\u4ef6\u65f6\uff0c\u53ef\u80fd\u4f1a\u6d89\u53ca\u5230\u5916\u90e8\u8d44\u6e90\u6587\u4ef6\uff08\u5982\u56fe\u50cf\u3001\u914d\u7f6e\u6587\u4ef6\u7b49\uff09\u7684\u7ba1\u7406\u3002\u4f7f\u7528PyInstaller\u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u5728.spec\u6587\u4ef6\u4e2d\u6307\u5b9a\u6570\u636e\u6587\u4ef6\u7684\u8def\u5f84\uff0c\u786e\u4fdd\u8fd9\u4e9b\u8d44\u6e90\u4e5f\u88ab\u5305\u542b\u5728\u6253\u5305\u7684\u7ed3\u679c\u4e2d\u3002\u53e6\u5916\uff0c\u53ef\u4ee5\u4f7f\u7528<code>--add-data<\/code>\u53c2\u6570\u6765\u624b\u52a8\u6dfb\u52a0\u8fd9\u4e9b\u6587\u4ef6\uff0c\u4f8b\u5982\uff1a<code>pyinstaller --add-data &quot;data.txt;.&quot; your_script.py<\/code>\uff0c\u786e\u4fdd\u5728exe\u8fd0\u884c\u65f6\u53ef\u4ee5\u8bbf\u95ee\u6240\u9700\u7684\u8d44\u6e90\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5c06Python\u7a0b\u5e8f\u5c01\u88c5\u6210exe\u6587\u4ef6\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5e38\u7528\u7684\u5de5\u5177\u5305\u62ecPyInstaller\u3001cx_Freeze\u3001py [&hellip;]","protected":false},"author":3,"featured_media":1161384,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1161373"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1161373"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1161373\/revisions"}],"predecessor-version":[{"id":1161388,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1161373\/revisions\/1161388"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1161384"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1161373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1161373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1161373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}