{"id":19945,"date":"2025-05-04T13:55:17","date_gmt":"2025-05-04T05:55:17","guid":{"rendered":"https:\/\/blog.iyatt.com\/?p=19945"},"modified":"2025-05-04T21:49:59","modified_gmt":"2025-05-04T13:49:59","slug":"windows-%e4%b8%8b-nuitka-%e6%98%af%e5%90%a6%e6%89%93%e5%8c%85%e7%8a%b6%e6%80%81%e5%88%a4%e6%96%ad%e5%8f%8a%e8%b7%af%e5%be%84%e8%8e%b7%e5%8f%96","status":"publish","type":"post","link":"https:\/\/blog.iyatt.com\/?p=19945","title":{"rendered":"Windows \u4e0b Nuitka \u662f\u5426\u6253\u5305\u72b6\u6001\u5224\u65ad\u53ca\u8def\u5f84\u83b7\u53d6"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-light-blue ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title ez-toc-toggle\" style=\"cursor:pointer\">\u76ee\u5f55<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/blog.iyatt.com\/?p=19945\/#%E6%B5%8B%E8%AF%95%E7%8E%AF%E5%A2%83\" >\u6d4b\u8bd5\u73af\u5883<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-1'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/blog.iyatt.com\/?p=19945\/#%E6%96%B9%E6%A1%88\" >\u65b9\u6848<\/a><ul class='ez-toc-list-level-2' ><li class='ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/blog.iyatt.com\/?p=19945\/#%E5%88%A4%E6%96%AD%E8%BF%90%E8%A1%8C%E6%97%B6%E6%98%AF%E6%89%93%E5%8C%85%E8%BF%98%E6%98%AF%E4%BB%A3%E7%A0%81%E7%8A%B6%E6%80%81\" >\u5224\u65ad\u8fd0\u884c\u65f6\u662f\u6253\u5305\u8fd8\u662f\u4ee3\u7801\u72b6\u6001<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/blog.iyatt.com\/?p=19945\/#%E8%8E%B7%E5%8F%96%E8%B5%84%E6%BA%90%E6%96%87%E4%BB%B6%E8%B7%AF%E5%BE%84\" >\u83b7\u53d6\u8d44\u6e90\u6587\u4ef6\u8def\u5f84<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/blog.iyatt.com\/?p=19945\/#%E7%A4%BA%E4%BE%8B_%E2%80%93_%E4%BB%A3%E7%A0%81%E7%9B%B4%E6%8E%A5%E6%89%A7%E8%A1%8C\" >\u793a\u4f8b &#8211; \u4ee3\u7801\u76f4\u63a5\u6267\u884c<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/blog.iyatt.com\/?p=19945\/#%E7%A4%BA%E4%BE%8B_%E2%80%93_Nuitka_%E6%89%93%E5%8C%85%E4%B8%BA%E5%8D%95%E6%96%87%E4%BB%B6\" >\u793a\u4f8b &#8211; Nuitka \u6253\u5305\u4e3a\u5355\u6587\u4ef6<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/blog.iyatt.com\/?p=19945\/#%E7%A4%BA%E4%BE%8B_%E2%80%93_Nuitka_%E6%89%93%E5%8C%85%E4%B8%BA%E5%A4%9A%E6%96%87%E4%BB%B6\" >\u793a\u4f8b &#8211; Nuitka \u6253\u5305\u4e3a\u591a\u6587\u4ef6<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/blog.iyatt.com\/?p=19945\/#%E7%94%9F%E6%88%90%E5%BD%93%E5%89%8D%E8%87%AA%E8%BA%AB%E7%9A%84%E6%89%A7%E8%A1%8C%E5%91%BD%E4%BB%A4\" >\u751f\u6210\u5f53\u524d\u81ea\u8eab\u7684\u6267\u884c\u547d\u4ee4<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h1><span class=\"ez-toc-section\" id=\"%E6%B5%8B%E8%AF%95%E7%8E%AF%E5%A2%83\"><\/span>\u6d4b\u8bd5\u73af\u5883<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<ul>\n<li>Windows 11 24H2<\/li>\n<li>Python 3.13.1<\/li>\n<li>Nuitka 2.7.0<\/li>\n<li>Nuitka 2.6.9<\/li>\n<\/ul>\n<h1><span class=\"ez-toc-section\" id=\"%E6%96%B9%E6%A1%88\"><\/span>\u65b9\u6848<span class=\"ez-toc-section-end\"><\/span><\/h1>\n<h2><span class=\"ez-toc-section\" id=\"%E5%88%A4%E6%96%AD%E8%BF%90%E8%A1%8C%E6%97%B6%E6%98%AF%E6%89%93%E5%8C%85%E8%BF%98%E6%98%AF%E4%BB%A3%E7%A0%81%E7%8A%B6%E6%80%81\"><\/span>\u5224\u65ad\u8fd0\u884c\u65f6\u662f\u6253\u5305\u8fd8\u662f\u4ee3\u7801\u72b6\u6001<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<ul>\n<li>\u6253\u5305\u72b6\u6001\u4e0b\uff0csys.argv[0] \u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u7684\u8def\u5f84\uff0c\u6269\u5c55\u540d\u662f .exe<\/li>\n<li>\u4ee3\u7801\u72b6\u6001\u4e0b\uff0csys.argv[0] \u4e3a\u4ee3\u7801\u6587\u4ef6\u7684\u8def\u5f84\uff0c\u6269\u5c55\u540d\u662f .py<br \/>\n\u6839\u636e\u8fd9\u4e2a\u7279\u70b9\u53ef\u4ee5\u8fdb\u884c\u5224\u65ad\uff0c\u4e0b\u9762\u7684\u53d8\u91cf isPackaged \u503c\u4e3a True \u4ee3\u8868\u662f Nuitka \u6253\u5305\u7684\u72b6\u6001\uff0cFalse \u4e3a\u4ee3\u7801\u72b6\u6001<\/li>\n<\/ul>\n<pre><code class=\"language-python\">import sys\n\nisPackaged: bool = not sys.argv[0].endswith(&#039;.py&#039;)<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"%E8%8E%B7%E5%8F%96%E8%B5%84%E6%BA%90%E6%96%87%E4%BB%B6%E8%B7%AF%E5%BE%84\"><\/span>\u83b7\u53d6\u8d44\u6e90\u6587\u4ef6\u8def\u5f84<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>\u4e00\u822c\u4f1a\u628a\u7528\u5230\u7684\u8d44\u6e90\u6587\u4ef6\u653e\u5728\u7a0b\u5e8f\u6587\u4ef6\u7684\u540c\u76ee\u5f55\u6216\u5f80\u4e0b\u7684\u5b50\u76ee\u5f55\u4e2d\uff0c\u5728\u4ee3\u7801\u72b6\u6001\u4e0b\u5c31\u5f88\u7b80\u5355\uff0c\u53d6\u4ee3\u7801\u6587\u4ef6\u6240\u5728\u76ee\u5f55\u5373\u53ef\u3002<br \/>\nNuitka \u7528 &#8211;include-data-file= \u6253\u5305\u7684\u8d44\u6e90\u6587\u4ef6\u5c31\u5728\u4e0b\u9762\u7684 runtimeDir \u4e0b<\/p>\n<pre><code class=\"language-python\">import os\n\nruntimeDir = os.path.dirname(__file__)<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"%E7%A4%BA%E4%BE%8B_%E2%80%93_%E4%BB%A3%E7%A0%81%E7%9B%B4%E6%8E%A5%E6%89%A7%E8%A1%8C\"><\/span>\u793a\u4f8b &#8211; \u4ee3\u7801\u76f4\u63a5\u6267\u884c<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u6bd4\u5982\u4e0b\u9762\u4e3e\u4e00\u4e2a\u4f8b\u5b50<br \/>\ntest.py<\/p>\n<pre><code class=\"language-python\">import os\nimport tkinter\n\nruntimeDir = os.path.dirname(__file__)\n\nroot = tkinter.Tk()\nroot.iconbitmap(os.path.join(runtimeDir, &#039;icon.ico&#039;))\nroot.mainloop()<\/code><\/pre>\n<p>\u4ee3\u7801\u6587\u4ef6\u540c\u76ee\u5f55\u4e0b\u6709\u4e00\u4e2a\u56fe\u6807\u6587\u4ef6 icon.ico\uff0c\u76f4\u63a5\u7528 Python \u89e3\u91ca\u5668\u6267\u884c\uff0c\u6b63\u5e38\u8fd0\u884c\uff0c\u7a97\u53e3\u56fe\u6807\u4f7f\u7528\u7684 icon.ico<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/05\/image-1746337912448.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 527px; --smush-placeholder-aspect-ratio: 527\/131;\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E7%A4%BA%E4%BE%8B_%E2%80%93_Nuitka_%E6%89%93%E5%8C%85%E4%B8%BA%E5%8D%95%E6%96%87%E4%BB%B6\"><\/span>\u793a\u4f8b &#8211; Nuitka \u6253\u5305\u4e3a\u5355\u6587\u4ef6<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u7136\u540e\u7528\u4e0b\u9762\u547d\u4ee4\u6253\u5305\u4e3a\u5355\u6587\u4ef6<\/p>\n<pre><code class=\"language-bash\">nuitka --standalone --onefile --remove-output --enable-plugin=tk-inter --windows-icon-from-ico=.\\icon.ico --include-data-file=.\\icon.ico=.\\ --output-dir=dist --output-filename=test .\\test.py<\/code><\/pre>\n<p>\u53ef\u4ee5\u6b63\u5e38\u6267\u884c\uff0c\u7a97\u53e3\u56fe\u6807\u6b63\u5e38\u663e\u793a<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/05\/image-1746337739604.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 513px; --smush-placeholder-aspect-ratio: 513\/199;\" \/><\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/05\/image-1746359801960.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 570px; --smush-placeholder-aspect-ratio: 570\/180;\" \/><\/p>\n<h3><span class=\"ez-toc-section\" id=\"%E7%A4%BA%E4%BE%8B_%E2%80%93_Nuitka_%E6%89%93%E5%8C%85%E4%B8%BA%E5%A4%9A%E6%96%87%E4%BB%B6\"><\/span>\u793a\u4f8b &#8211; Nuitka \u6253\u5305\u4e3a\u591a\u6587\u4ef6<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>\u7528\u4e0b\u9762\u547d\u4ee4\u6253\u5305\u4e3a\u591a\u6587\u4ef6<\/p>\n<pre><code class=\"language-bash\">nuitka --standalone --remove-output --enable-plugin=tk-inter --windows-icon-from-ico=.\\icon.ico --include-data-file=.\\icon.ico=.\\ --output-dir=dist --output-filename=test .\\test.py<\/code><\/pre>\n<p>\u53ef\u4ee5\u6b63\u5e38\u6267\u884c\uff0c\u7a97\u53e3\u56fe\u6807\u6b63\u5e38\u663e\u793a<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/05\/image-1746338095233.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 580px; --smush-placeholder-aspect-ratio: 580\/141;\" \/><\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/05\/image-1746359723789.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 617px; --smush-placeholder-aspect-ratio: 617\/152;\" \/><\/p>\n<h2><span class=\"ez-toc-section\" id=\"%E7%94%9F%E6%88%90%E5%BD%93%E5%89%8D%E8%87%AA%E8%BA%AB%E7%9A%84%E6%89%A7%E8%A1%8C%E5%91%BD%E4%BB%A4\"><\/span>\u751f\u6210\u5f53\u524d\u81ea\u8eab\u7684\u6267\u884c\u547d\u4ee4<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<pre><code class=\"language-python\">import sys\nimport os\n\nisPackaged: bool = not sys.argv[0].endswith(&#039;.py&#039;)\n\nif isPackaged:\n    exePath = sys.argv[0]\nelse:\n    exePath = f&#039;{sys.executable} {os.path.abspath(sys.argv[0])}&#039;\n\nprint(f&#039;\u5f53\u524d\u7684\u6267\u884c\u547d\u4ee4\u4e3a\uff1a{exePath}&#039;)<\/code><\/pre>\n<p>Python \u89e3\u91ca\u5668\u76f4\u63a5\u6267\u884c<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/05\/image-1746359307281.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 947px; --smush-placeholder-aspect-ratio: 947\/115;\" \/><\/p>\n<p>Nuitka \u6253\u5305\u4e3a\u591a\u6587\u4ef6<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/05\/image-1746359222072.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 611px; --smush-placeholder-aspect-ratio: 611\/104;\" \/><\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/05\/image-1746359441096.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 610px; --smush-placeholder-aspect-ratio: 610\/108;\" \/><\/p>\n<p>Nuitka \u6253\u5305\u4e3a\u5355\u6587\u4ef6<br \/>\n<img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/05\/image-1746359266660.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 541px; --smush-placeholder-aspect-ratio: 541\/115;\" \/><\/p>\n<p><img decoding=\"async\" data-src=\"https:\/\/blog.iyatt.com\/wp-content\/uploads\/2025\/05\/image-1746359492581.png\" alt=\"file\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" style=\"--smush-placeholder-width: 533px; --smush-placeholder-aspect-ratio: 533\/108;\" \/><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6d4b\u8bd5\u73af\u5883 Windows 11 24H2 Python 3.13.1 Nuitka 2.7.0 Nuitka  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"zakra_page_container_layout":"customizer","zakra_page_sidebar_layout":"customizer","zakra_remove_content_margin":false,"zakra_sidebar":"customizer","zakra_transparent_header":"customizer","zakra_logo":0,"zakra_main_header_style":"default","zakra_menu_item_color":"","zakra_menu_item_hover_color":"","zakra_menu_item_active_color":"","zakra_menu_active_style":"","zakra_page_header":true,"_lmt_disableupdate":"no","_lmt_disable":"no","footnotes":""},"categories":[1,592],"tags":[],"class_list":["post-19945","post","type-post","status-publish","format-standard","hentry","category-all","category-python"],"modified_by":"IYATT-yx","_links":{"self":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/19945","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=19945"}],"version-history":[{"count":10,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/19945\/revisions"}],"predecessor-version":[{"id":19994,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=\/wp\/v2\/posts\/19945\/revisions\/19994"}],"wp:attachment":[{"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=19945"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=19945"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.iyatt.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=19945"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}