{"id":516,"date":"2023-07-08T12:22:26","date_gmt":"2023-07-08T04:22:26","guid":{"rendered":"https:\/\/fugary.com\/?p=516"},"modified":"2023-07-08T12:24:42","modified_gmt":"2023-07-08T04:24:42","slug":"python%e4%bd%bf%e7%94%a8pyinstaller%e6%89%93%e5%8c%85exe%e5%92%8c%e4%be%9d%e8%b5%96%ef%bc%8c%e5%b9%b6%e5%ae%9e%e7%8e%b0%e7%89%88%e6%9c%ac%e7%ae%a1%e7%90%86","status":"publish","type":"post","link":"https:\/\/fugary.com\/?p=516","title":{"rendered":"Python\u4f7f\u7528PyInstaller\u6253\u5305exe\u548c\u4f9d\u8d56\uff0c\u5e76\u5b9e\u73b0\u7248\u672c\u7ba1\u7406"},"content":{"rendered":"<p>\u6700\u8fd1\u516c\u53f8\u7684\u4e00\u4e2a<code>Python<\/code>\u5199\u7684<code>GUI<\/code>\u5de5\u5177\u9700\u8981\u5206\u53d1\u7ed9\u516c\u53f8\u5458\u5de5\u4f7f\u7528\uff0c\u76ee\u524d\u4f7f\u7528\u5355\u6587\u4ef6\u6253\u5305\u6a21\u5f0f\uff0c\u751f\u6210\u4e00\u4e2a<code>exe<\/code>\u6587\u4ef6\uff08\u4ec5<code>Windows<\/code>\u4e0b\u4f7f\u7528\uff09\uff0c\u6253\u5305\u4e4b\u540e\u8fd8\u6709\u90e8\u5206\u4f9d\u8d56\u7684\u6587\u4ef6\u548c\u6587\u4ef6\u5939\u9700\u8981\u4e00\u8d77\u5206\u53d1\uff0c\u76ee\u524d\u5206\u53d1\u4ee5\u53ca\u540e\u9762\u7684\u81ea\u52a8\u66f4\u65b0\u4e0d\u662f\u5f88\u65b9\u4fbf\uff0c\u56e0\u6b64\u4f7f\u7528<code>Python<\/code>\u518d\u5199\u4e86\u4e00\u4e2a\u6253\u5305\u811a\u672c\u7b80\u5316\u6253\u5305\u64cd\u4f5c\u3002<\/p>\n<h3>\u4e3b\u8981\u529f\u80fd<\/h3>\n<ol>\n<li>\u4f7f\u7528<code>PyInstaller<\/code>\u6253\u5305\u6210\u5355\u4e2a<code>exe<\/code>\u6587\u4ef6<\/li>\n<li><code>exe<\/code>\u8981\u652f\u6301<code>Windows<\/code>\u7684\u5c5e\u6027\u67e5\u770b\u7248\u672c\u4fe1\u606f<\/li>\n<li>\u628a<code>exe<\/code>\u6587\u4ef6\u548c\u4f9d\u8d56\u6587\u4ef6\u548c\u6587\u4ef6\u5939\u6253\u5305\u6210\u4e00\u4e2a<code>zip<\/code>\u6587\u4ef6<\/li>\n<li>\u53d1\u5e03\u540e\u652f\u6301\u68c0\u67e5\u7248\u672c\u66f4\u65b0<\/li>\n<\/ol>\n<h3>PyInstaller\u6253\u5305<\/h3>\n<p><code>PyInstaller<\/code>\u6587\u6863\uff1a<a href=\"https:\/\/pyinstaller.org\/en\/stable\/usage.html\">https:\/\/pyinstaller.org\/en\/stable\/usage.html<\/a><\/p>\n<p>\u76ee\u524d\u4f7f\u7528\u547d\u4ee4\u884c\u901a\u8fc7<code>pyinstaller<\/code>\u547d\u4ee4\u6253\u5305\uff0c\u8981\u628a\u6253\u5305\u529f\u80fd\u96c6\u6210\u5230<code>build.py<\/code>\u811a\u672c\u4e2d\uff0c\u6700\u597d\u4f7f\u7528<code>Python<\/code>\u4ee3\u7801\u5b9e\u73b0\u6253\u5305<\/p>\n<h4>\u547d\u4ee4\u884c\u6253\u5305<\/h4>\n<p><strong>\u6ce8\u610f\uff1a\u5982\u679c\u5b89\u88c5\u540e\u6ca1\u6709<code>pyinstaller<\/code>\u547d\u4ee4\uff0c\u53ef\u80fd\u662f\u975e\u7ba1\u7406\u5458\u7528\u6237\uff0c\u53c8\u6ca1\u6709\u3010\u4ee5\u7ba1\u7406\u5458\u8eab\u4efd\u8fd0\u884c\u3011<code>pip<\/code>\u5b89\u88c5\u547d\u4ee4<\/strong><\/p>\n<p>\u547d\u4ee4\u884c\u6253\u5305\uff08<code>-F<\/code>\u662f\u6253\u5305\u6210\u5355\u6587\u4ef6\uff0c<code>-w<\/code>\u662f\u4ee5\u7a97\u53e3\u6a21\u5f0f\u8fd0\u884c\uff09\uff1a<\/p>\n<pre><code class=\"language-sh\">pip install pyinstaller\npyinstaller -F -w app.py<\/code><\/pre>\n<h4>\u4ee3\u7801\u6253\u5305<\/h4>\n<p>\u4f7f\u7528<code>Python<\/code>\u4ee3\u7801\u6253\u5305\uff0c\u9700\u8981\u5bfc\u5165<code>PyInstaller<\/code>\u7684<code>__main__<\/code>\u6a21\u5757\uff0c\u7136\u540e\u7528<code>__main__<\/code>\u7684<code>run<\/code>\u65b9\u6cd5\uff0c\u53c2\u6570\u4f20\u9012\u662f\u4ee5\u6570\u7ec4\u7684\u5f62\u5f0f\u4f20\u9012\uff0c\u6bd4\u8f83\u65b9\u4fbf<\/p>\n<p>\u8fd9\u91cc\u4f7f\u7528<code>config.py<\/code>\u6587\u4ef6\u914d\u7f6e\u8f6f\u4ef6\u7684\u56fe\u6807\u4ee5\u53ca<code>Windows<\/code>\u7684<code>version<\/code>\u6587\u4ef6\uff0c\u540e\u9762\u4f1a\u4ecb\u7ecd\u5982\u4f55\u83b7\u53d6\u5230<code>Windows<\/code>\u7684<code>version<\/code>\u6587\u4ef6<\/p>\n<pre><code class=\"language-python\">from PyInstaller import __main__\n\ndef pyinstaller_package():\n    # \u4f7f\u7528pyinstaller\u6253\u5305\n    __main__.run([&#039;-F&#039;, &#039;-w&#039;, f&#039;--icon={config.ICO_FILE}&#039;, f&#039;--version-file={config.VERSION_FILE_TXT}&#039;, &#039;app.py&#039;])<\/code><\/pre>\n<p>\u8fd9\u6837\u5c31\u5b9e\u73b0\u4e86\u7528<code>build.py<\/code>\u6587\u4ef6\u6253\u5305\u6210\u5355\u4e2a\u6587\u4ef6<code>exe<\/code><\/p>\n<h3>\u7248\u672c\u7ba1\u7406<\/h3>\n<p>\u8981\u5b9e\u73b0\u7248\u672c\u7ba1\u7406\u4ee5\u53ca\u7248\u672c\u68c0\u67e5\u66f4\u65b0\uff0c\u8fd9\u91cc\u4f7f\u7528\u4e00\u4e2a<code>versions.py<\/code>\u6587\u4ef6\u8bb0\u5f55\u9700\u8981\u53d1\u5e03\u7684\u7248\u672c\uff0c\u7136\u540e\u751f\u6210\u4e00\u4e2a<code>versions.json<\/code>\u6587\u4ef6\uff0c\u548c<code>zip<\/code>\u6587\u4ef6\u4e00\u8d77\u53d1\u5e03\u5230\u670d\u52a1\u5668\u4e0a\u3002<\/p>\n<p><div class='fancybox-wrapper' data-fancybox='post-images' href='https:\/\/git.mengqingpo.com:8888\/\/fugary\/blogpic\/uploads\/a9c70e01befe25dad5cd0a0aef83ef04\/%E7%89%88%E6%9C%AC%E7%AE%A1%E7%90%86.png'><img src=\"https:\/\/git.mengqingpo.com:8888\/\/fugary\/blogpic\/uploads\/a9c70e01befe25dad5cd0a0aef83ef04\/%E7%89%88%E6%9C%AC%E7%AE%A1%E7%90%86.png\" alt=\"\u7248\u672c\u7ba1\u7406\" \/><\/div><\/p>\n<p>\u4e00\u822c\u60c5\u51b5\u4e0b\u7248\u672c\u7ba1\u7406\u53ef\u4ee5\u653e\u5230\u6570\u636e\u5e93\uff0c\u4f46\u662f\u56e0\u4e3a\u5de5\u5177\u6bd4\u8f83\u5c0f\uff0c\u6ca1\u6709\u5fc5\u8981\u641e\u90a3\u4e48\u590d\u6742\uff0c\u56e0\u6b64\u7528<code>versions.py<\/code>\u6587\u4ef6\u7ba1\u7406\u7248\u672c\u5217\u8868\uff0c\u6bcf\u6b21\u53d1\u5e03\u7684\u65f6\u5019\u65b0\u589e\u4e00\u6761\u53d1\u5e03\u7248\u672c\u8bb0\u5f55\u5373\u53ef\u3002<\/p>\n<h4>\u7248\u672c\u5217\u8868<\/h4>\n<pre><code class=\"language-python\">import config\n\nrelease_list = [{\n    &quot;version&quot;: &quot;1.0.1&quot;,\n    &quot;publishDate&quot;: &quot;2023-07-07 10:00&quot;,\n    &quot;forceUpdate&quot;: True,\n    &quot;publishNotes&quot;: [&quot;1. \u7248\u672c\u66f4\u65b0&quot;, &quot;2. \u7248\u672c1.0.1&quot;, &quot;3. \u66f4\u65b0\u5185\u5bb9\uff1axxxx&quot;],\n    &quot;updateUrl&quot;: f&#039;{config.INTERNAL_DOWNLOAD_URL}\/app.1.0.1.20230707.zip&#039;\n}, {\n    &quot;version&quot;: &quot;1.0.0&quot;,\n    &quot;publishDate&quot;: &quot;2023-07-05 17:00&quot;,\n    &quot;forceUpdate&quot;: True,\n    &quot;publishNotes&quot;: [&quot;1. \u521d\u59cb\u7248\u672c&quot;, &quot;2. \u751f\u62101.0.0&quot;, &quot;3. \u66f4\u65b0\u5185\u5bb9\uff1axxxx&quot;],\n    &quot;updateUrl&quot;: f&#039;{config.INTERNAL_DOWNLOAD_URL}\/app.1.0.0.20230705.zip&#039;\n}]\n\ncurrent_version = release_list[0][&#039;version&#039;]\n<\/code><\/pre>\n<h4>\u751f\u6210<code>versions.json<\/code><\/h4>\n<p>\u901a\u8fc7<code>versions.py<\/code>\u91cc\u9762\u7684<code>release_list<\/code>\u4fe1\u606f\u751f\u6210\u4e00\u4e2a<code>json<\/code>\u6587\u4ef6\uff0c\u8fd9\u4e2a\u6587\u4ef6\u6700\u540e\u53d1\u5e03\u5230<code>Nginx<\/code>\u670d\u52a1\uff0c\u7528\u4e8e\u68c0\u67e5\u7248\u672c<\/p>\n<pre><code class=\"language-python\">import json\nimport os\nfrom versions import release_list, current_version\n\ndef generate_version_json(dist_path):\n    versions_json = json.dumps(release_list, indent=4, ensure_ascii=False)\n    if not os.path.exists(dist_path):\n        os.mkdir(dist_path)\n    with open(os.path.join(dist_path, &#039;versions.json&#039;), &#039;w&#039;, encoding=&quot;utf8&quot;) as json_file:\n        json_file.write(versions_json)<\/code><\/pre>\n<p>\u751f\u6210\u7684<code>versions.json<\/code>\u793a\u4f8b\uff0c\u653e\u5230<code>Nginx<\/code>\u670d\u52a1\u5668\u4e0a\u80fd\u591f\u901a\u8fc7<code>URL<\/code>\u8bbf\u95ee\u5230\u5c31\u53ef\u4ee5<\/p>\n<pre><code class=\"language-json\">[\n    {\n        &quot;version&quot;: &quot;1.0.1&quot;,\n        &quot;publishDate&quot;: &quot;2023-07-07 10:00&quot;,\n        &quot;forceUpdate&quot;: true,\n        &quot;publishNotes&quot;: [\n            &quot;1. \u7248\u672c\u66f4\u65b0&quot;,\n            &quot;2. \u7248\u672c1.0.1&quot;,\n            &quot;3. \u66f4\u65b0\u5185\u5bb9\uff1axxxx&quot;\n        ],\n        &quot;updateUrl&quot;: &quot;https:\/\/xxxxx\/app.1.0.1.xxxx.zip&quot;\n    },\n    {\n        &quot;version&quot;: &quot;1.0.0&quot;,\n        &quot;publishDate&quot;: &quot;2023-07-05 17:00&quot;,\n        &quot;forceUpdate&quot;: true,\n        &quot;publishNotes&quot;: [\n            &quot;1. \u521d\u59cb\u7248\u672c&quot;,\n            &quot;2. \u751f\u62101.0.0&quot;,\n            &quot;3. \u66f4\u65b0\u5185\u5bb9\uff1axxxx&quot;\n        ],\n        &quot;updateUrl&quot;: &quot;https:\/\/xxxx\/app.1.0.0.xxxx.zip&quot;\n    }\n]<\/code><\/pre>\n<h3>Windows\u7248\u672c\u6587\u4ef6<\/h3>\n<p>\u4e3a\u4e86\u4f7f<code>exe<\/code>\u6587\u4ef6\u770b\u8d77\u6765\u6bd4\u8f83\u6b63\u5f0f\uff0c\u53ef\u4ee5\u8003\u8651\u589e\u52a0\u56fe\u6807\u4ee5\u53ca<code>Windows<\/code>\u7684\u7248\u672c\u6587\u4ef6\uff0c\u6253\u5305\u540e\u5c31\u6709\u7248\u6743\u7b49\u4fe1\u606f\u4e86\u3002<\/p>\n<h4>\u4ec0\u4e48\u662f\u7248\u672c\u6587\u4ef6<\/h4>\n<p>\u901a\u5e38\u5728Windows\u7cfb\u7edf\u4e0b\uff0c\u4e00\u4e2a<code>exe<\/code>\u6587\u4ef6\u901a\u8fc7\u5c5e\u6027\u53ef\u4ee5\u770b\u5230\u8f6f\u4ef6\u7684\u4f5c\u8005\u3001\u7248\u672c\u3001\u7248\u6743\u7b49\u7b49\u4fe1\u606f\uff0c\u6211\u4eec\u81ea\u5df1\u7528<code>PyInstaller<\/code>\u6253\u5305\u7684<code>exe<\/code>\u6587\u4ef6\u5982\u679c\u6ca1\u6709\u6307\u5b9a<code>\u2013version-file<\/code>\u7684\u8bdd\uff0c\u5c5e\u6027\u91cc\u9762\u6ca1\u6709\u8fd9\u6837\u7684\u4fe1\u606f\uff0c\u5982\u56fe\uff1a<\/p>\n<p><div class='fancybox-wrapper' data-fancybox='post-images' href='https:\/\/git.mengqingpo.com:8888\/\/fugary\/blogpic\/uploads\/73550ab72885da81474f1fa05946f3ed\/image-20230708113615921.png'><img src=\"https:\/\/git.mengqingpo.com:8888\/\/fugary\/blogpic\/uploads\/73550ab72885da81474f1fa05946f3ed\/image-20230708113615921.png\" alt=\"image-20230708113615921\" \/><\/div><\/p>\n<h4>\u6293\u53d6\u7248\u672c\u4fe1\u606f<\/h4>\n<p>\u5b89\u88c5\u597d<code>PyInstaller<\/code>\u4e4b\u540e\u5728<code>Python<\/code>\u7684\u5b89\u88c5\u76ee\u5f55\u4e0b\u9762\u7684<code>Scripts<\/code>\u4e2d\u4f1a\u6709\u4e00\u4e2a<code>pyi-grab_version.exe<\/code>\u6587\u4ef6\uff0c\u53ef\u4ee5\u6293\u53d6\u5176\u4ed6\u7b2c\u4e09\u65b9\u7684<code>exe<\/code>\uff08\u6211\u8fd9\u91cc\u4f7f\u7528\u7684\u8fc5\u96f7\uff09\u7684\u7248\u672c\u4fe1\u606f\uff0c\u5e76\u751f\u6210\u4e00\u4e2a<code>file_version_info.txt<\/code>\u6587\u4ef6\uff0c\u6211\u4eec\u53ef\u4ee5\u8fd9\u4e2a\u7248\u672c\u6587\u4ef6\u4e3a\u57fa\u7840\uff0c\u4fee\u6539\u4e3a\u81ea\u5df1\u7684\u7248\u672c\u6587\u4ef6<\/p>\n<pre><code class=\"language-sh\">pyi-grab_version.exe &quot;C:\\softs\\Thunder Network\\Thunder\\Program\\Thunder.exe&quot;<\/code><\/pre>\n<p>\u7248\u672c\u6587\u4ef6\u5982\u4e0b\uff0c\u5982\u679c\u81ea\u5df1\u751f\u6210\u5931\u8d25\uff0c\u53ef\u4ee5\u76f4\u63a5\u7528\u8fd9\u91cc\u8d34\u51fa\u6765\u7684\u6587\u4ef6\u4fe1\u606f\u505a\u4fee\u6539\uff1a<\/p>\n<pre><code class=\"language-python\"># UTF-8\n#\n# For more details about fixed file info &#039;ffi&#039; see:\n# http:\/\/msdn.microsoft.com\/en-us\/library\/ms646997.aspx\nVSVersionInfo(\n  ffi=FixedFileInfo(\n    # filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4)\n    # Set not needed items to zero 0.\n    filevers=(11, 4, 7, 2104),\n    prodvers=(11, 4, 7, 2104),\n    # Contains a bitmask that specifies the valid bits &#039;flags&#039;r\n    mask=0x3f,\n    # Contains a bitmask that specifies the Boolean attributes of the file.\n    flags=0x0,\n    # The operating system for which this file was designed.\n    # 0x4 - NT and there is no need to change it.\n    OS=0x40004,\n    # The general type of file.\n    # 0x1 - the file is an application.\n    fileType=0x1,\n    # The function of the file.\n    # 0x0 - the function is not defined for this fileType\n    subtype=0x0,\n    # Creation date and time stamp.\n    date=(0, 0)\n    ),\n  kids=[\n    StringFileInfo(\n      [\n      StringTable(\n        &#039;080404b0&#039;,\n        [StringStruct(&#039;CompanyName&#039;, &#039;\u6df1\u5733\u5e02\u8fc5\u96f7\u7f51\u7edc\u6280\u672f\u6709\u9650\u516c\u53f8&#039;),\n        StringStruct(&#039;FileDescription&#039;, &#039;\u8fc5\u96f711&#039;),\n        StringStruct(&#039;FileVersion&#039;, &#039;11,4,7,2104&#039;),\n        StringStruct(&#039;InternalName&#039;, &#039;Thunder 2&#039;),\n        StringStruct(&#039;LegalCopyright&#039;, &#039;\u7248\u6743\u6240\u6709 (C) 2023 \u6df1\u5733\u5e02\u8fc5\u96f7\u7f51\u7edc\u6280\u672f\u6709\u9650\u516c\u53f8&#039;),\n        StringStruct(&#039;OriginalFilename&#039;, &#039;Thunder&#039;),\n        StringStruct(&#039;ProductName&#039;, &#039;\u8fc5\u96f711&#039;),\n        StringStruct(&#039;ProductVersion&#039;, &#039;11.4.7.2104&#039;),\n        StringStruct(&#039;LegalTrademarks&#039;, &#039;\u8fc5\u96f711&#039;),\n        StringStruct(&#039;SpecialBuild&#039;, &#039;100017&#039;)])\n      ]), \n    VarFileInfo([VarStruct(&#039;Translation&#039;, [2052, 1200])])\n  ]\n)<\/code><\/pre>\n<h4>\u81ea\u52a8\u5199\u5165<\/h4>\n<p>\u4fee\u6539\u597d\u57fa\u672c\u4fe1\u606f\u4e4b\u540e\uff0c\u53ef\u4ee5\u5728\u6253\u5305\u7684\u65f6\u5019\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u66ff\u6362\u7248\u672c\u4fe1\u606f\uff0c\u81ea\u52a8\u5b9e\u73b0\u65b0\u7248\u672c\u4fe1\u606f\u5199\u5165<code>file_version_info.txt<\/code><\/p>\n<pre><code class=\"language-python\">def process_version_info():\n    ver = current_version.split(&#039;.&#039;)\n    with open(&#039;file_version_info.txt&#039;, &#039;r+&#039;, encoding=&#039;utf8&#039;) as ver_file:\n        txt = ver_file.read()\n        txt = re.sub(&#039;\\\\(\\\\d+, \\\\d+, \\\\d+, 0\\\\),&#039;, f&#039;({ver[0]}, {ver[1]}, {ver[2]}, 0),&#039;, txt)\n        txt = re.sub(&quot;u&#039;\\\\d+\\\\.\\\\d+\\\\.\\\\d+\\\\.0&#039;&quot;, f&quot;u&#039;{current_version}.0&#039;&quot;, txt)\n        txt = re.sub(&quot;\\\\(u&#039;FileDescription&#039;, u&#039;.+&#039;\\\\)&quot;, f&quot;(u&#039;FileDescription&#039;, u&#039;{config.PRODUCT_NAME}&#039;)&quot;, txt)\n        txt = re.sub(&quot;\\\\(u&#039;ProductName&#039;, u&#039;.+&#039;\\\\)&quot;, f&quot;(u&#039;ProductName&#039;, u&#039;{config.PRODUCT_NAME}&#039;)&quot;, txt)\n        ver_file.seek(0)\n        ver_file.truncate()\n        ver_file.write(txt)<\/code><\/pre>\n<h3>\u6253\u5305zip<\/h3>\n<p>\u901a\u8fc7<code>PyInstaller<\/code>\u6253\u5305\u751f\u6210\u7684<code>app.exe<\/code>\u5df2\u7ecf\u5728<code>dist<\/code>\u76ee\u5f55\uff0c\u6211\u4eec\u9700\u8981\u628a<code>app.exe<\/code>\u548c\u4f9d\u8d56\u7684\u6587\u4ef6\u6216\u6587\u4ef6\u5939\u6253\u5305\u6210<code>zip<\/code>\u6587\u4ef6\uff0c\u5e76\u653e\u5230<code>dist<\/code>\u76ee\u5f55\uff0c\u6253\u5305\u4ee3\u7801\uff1a<\/p>\n<pre><code class=\"language-python\">import os\nimport shutil\nimport time\nimport zipfile\n\nOUT_PATH = &#039;dist&#039;  # \u8f93\u51fa\u8def\u5f84\nZIP_FILES = [&#039;files&#039;, &#039;resources&#039;, &#039;dist\\\\app.exe&#039;, &#039;data.xlsx&#039;]  # \u538b\u7f29\u5305\u9700\u8981\u6587\u4ef6\nCLEAN_PATH = [&#039;dist&#039;, &#039;build&#039;]  # \u6e05\u7406\u8def\u5f84\n\ndef zip_dir_list(input_path_list: list, output_file):\n    with zipfile.ZipFile(output_file, &quot;w&quot;, zipfile.ZIP_DEFLATED) as output_zip:\n        for input_path in input_path_list:\n            if os.path.isdir(input_path):\n                zip_dir(input_path, output_zip)\n            elif os.path.isfile(input_path):\n                filename = input_path.split(os.sep)[-1]\n                print(&#039;zip adding file %s&#039; % input_path)\n                output_zip.write(input_path, filename)\n\ndef zip_dir(input_path, output_zip):\n    for path, dir_names, file_names in os.walk(input_path):\n        for filename in file_names:\n            full_path = os.path.join(path, filename)\n            print(&#039;zip adding file %s&#039; % full_path)\n            # \u6587\u4ef6\u8def\u5f84\uff0c\u538b\u7f29\u8def\u5f84\n            output_zip.write(full_path)\n\nif __name__ == &#039;__main__&#039;:\n    date_str = time.strftime(&#039;%Y%m%d&#039;)\n    zip_dir_list(ZIP_FILES, f&#039;{OUT_PATH}\/app.{current_version}.{date_str}.zip&#039;)  # zip\u6253\u5305\u76f8\u5173\u6587\u4ef6<\/code><\/pre>\n<p>\u628a\u9700\u8981\u6253\u5305\u7684\u6587\u4ef6\u5199\u5230<code>ZIP_FILES<\/code>\u5217\u8868\u4e2d\u5373\u53ef\u3002<\/p>\n<p>\u5b8c\u6574\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<pre><code class=\"language-python\">def clean_last_build():\n    # \u6e05\u7406\u4e0a\u6b21\u6587\u4ef6\n    for c_path in CLEAN_PATH:\n        if os.path.exists(c_path):\n            print(&#039;clean path %s&#039; % c_path)\n            shutil.rmtree(c_path)\n\nif __name__ == &#039;__main__&#039;:\n    clean_last_build()  # \u6e05\u7406\u4e0a\u6b21\u6784\u5efa\u76ee\u5f55\n    generate_version_json(OUT_PATH)  # \u751f\u6210\u7248\u672c\u6587\u4ef6\n    process_version_info()  # \u5904\u7406windows\u7248\u672c\u751f\u6210\u6587\u4ef6\n    pyinstaller_package()  # \u8c03\u7528pyinstaller\u6253\u5305\n    date_str = time.strftime(&#039;%Y%m%d&#039;)\n    zip_dir_list(ZIP_FILES, f&#039;{OUT_PATH}\/app.{current_version}.{date_str}.zip&#039;)  # zip\u6253\u5305\u76f8\u5173\u6587\u4ef6\n    print(&#039;\u6253\u5305\u5b8c\u6210\uff01&#039;)<\/code><\/pre>\n<p><code>build.py<\/code>\u4e3b\u8981\u5c31\u662f\u6309\u7167\u987a\u5e8f\u8c03\u7528\u5404\u4e2a\u6b65\u9aa4\u7684\u65b9\u6cd5\u5b9e\u73b0\u6574\u4e2a\u6253\u5305\u8fc7\u7a0b<\/p>\n<h3>\u68c0\u67e5\u66f4\u65b0<\/h3>\n<p>\u68c0\u67e5\u7248\u672c\u66f4\u65b0\uff0c\u8fd9\u91cc\u4f7f\u7528<code>semver<\/code>\u5224\u65ad\u662f\u5426\u6709\u65b0\u7248\u672c\uff1a<\/p>\n<pre><code class=\"language-python\">import requests\nimport semver\n\nclass Updater:\n    def __init__(self, base_url: str):\n        self.base_url = base_url\n    def check_for_update(self, version):\n        check_url = self.base_url + &#039;\/versions.json&#039;\n        res = requests.get(check_url).json()\n        if len(res) and semver.compare(res[0][&#039;version&#039;], version) &gt; 0:\n            return res[0]\nif __name__ == &#039;__main__&#039;:\n    updater = Updater(&#039;https:\/\/xxxx\/app&#039;)\n    result = updater.check_for_update(&#039;1.0.0&#039;)\n    if result is not None:\n        print(&#039;\u6709\u65b0\u7248\u672c\uff1a&#039;, result)\n    else:\n        print(&#039;\u5df2\u7ecf\u662f\u6700\u65b0\u7248\u672c&#039;)<\/code><\/pre>\n<p>\u8fd9\u6837\u5c31\u5b9e\u73b0\u4e86\u68c0\u67e5\u7248\u672c\u66f4\u65b0\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u516c\u53f8\u7684\u4e00\u4e2aPython\u5199\u7684GUI\u5de5\u5177\u9700\u8981\u5206\u53d1\u7ed9\u516c\u53f8\u5458\u5de5\u4f7f\u7528\uff0c\u76ee\u524d\u4f7f\u7528\u5355\u6587\u4ef6\u6253\u5305\u6a21\u5f0f\uff0c\u751f\u6210\u4e00\u4e2aexe\u6587\u4ef6\uff08\u4ec5 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[123,122,101,124],"_links":{"self":[{"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/posts\/516"}],"collection":[{"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fugary.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=516"}],"version-history":[{"count":2,"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/posts\/516\/revisions"}],"predecessor-version":[{"id":518,"href":"https:\/\/fugary.com\/index.php?rest_route=\/wp\/v2\/posts\/516\/revisions\/518"}],"wp:attachment":[{"href":"https:\/\/fugary.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=516"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fugary.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=516"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fugary.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=516"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}