{"id":566,"date":"2015-12-15T08:17:09","date_gmt":"2015-12-15T00:17:09","guid":{"rendered":"http:\/\/www.datarelab.com\/blog\/?p=566"},"modified":"2015-12-15T08:18:40","modified_gmt":"2015-12-15T00:18:40","slug":"%e4%bd%bf%e7%94%a8-pyinstaller-%e6%8a%8apython%e7%a8%8b%e5%ba%8f-py%e8%bd%ac%e4%b8%ba-exe-%e5%8f%af%e6%89%a7%e8%a1%8c%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/www.datarelab.com\/blog\/Technical_literature\/566.html","title":{"rendered":"\u4f7f\u7528 PyInstaller \u628apython\u7a0b\u5e8f .py\u8f6c\u4e3a .exe \u53ef\u6267\u884c\u7a0b\u5e8f"},"content":{"rendered":"<p>\u6700\u8fd1\u4f7f\u7528Python\u4e3a\u9879\u76ee\u5f00\u53d1\u4e00\u6b3e\u7ed8\u56fe\u5de5\u5177(\u7ed8\u51fa \u58f0\u573a\u4e09\u7ef4\u6a21\u578b)\u3002\u56e0\u4e3a\u5e0c\u671b\u80fd\u628aPython\u811a\u672c\u53d1\u5e03\u4e3a\u8131\u79bbPython\u5e73\u53f0\u8fd0\u884c\u7684\u53ef\u6267\u884c\u7a0b\u5e8f\uff0c\u6bd4\u5982\u5355\u4e2a\u7684exe\u6587\u4ef6\u3002PyInstaller\u6070\u6ee1\u8db3\u8fd9\u4e2a\u9700\u6c42\u3002\u672c\u6587PyInstaller\u7684\u7248\u672c\u662f2.0\uff0c\u652f\u6301Python2.7\u3002\u4e0b\u9762\u8ba8\u8bba\u600e\u6837\u5b89\u88c5\uff0c\u4f7f\u7528PyInstaller\u3002PyInstaller\u672c\u8eab\u5e76\u4e0d\u5c5e\u4e8ePython\u5305\u3002\u5728\u5b89\u88c5 pyinstaller \u4e4b\u524d\u5047\u8bbe\u4f60\u5df2\u7ecf\u5b89\u88c5\u4e86python \uff0c\u6ce8\u610f\u628apython \u73af\u5883\u53d8\u91cf\u914d\u7f6e\u597d, \u5373 \u8fdb\u5165cmd\u540e \u8f93\u5165 python \u4f1a\u8fdb\u5165 python shell.<br \/>\npyinstaller\u5b89\u88c5\uff1a<br \/>\n1\uff0c\u4e0b\u8f7dpyinstaller\u5e76\u89e3\u538b\uff08\u53ef\u4ee5\u53bb\u5b98\u7f51\u4e0b\u8f7d\u6700\u65b0\u7248\uff09\uff1a<br \/>\n2\uff0c\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684 pywin32-217.win32-py2.7.exe\uff1a<br \/>\n\u4e0d\u7136\u4f1a\u51fa\u73b0\u9519\u8befError: PyInstaller for Python 2.6+ on Windows needs pywin32.<br \/>\n3,\u8fdb\u5165cmd ,<br \/>\n<strong>d:\\&gt;cd d:\\PyInstaller-2.1<\/strong><br \/>\n<strong>d:\\pyinstaller&gt;python pyinstaller.py<\/strong><br \/>\nUsage: python pyinstaller.py [opts] &lt;scriptname&gt; [ &lt;scriptname&gt; ...] | &lt;specfile&gt;<br \/>\npyinstaller.py: error: Requires at least one scriptname file or exactly one .spec-file<br \/>\n\u4ee5\u4e0a\u4fe1\u606f\u8868\u793a\u53ef\u4ee5\u5f00\u5c55\u5de5\u4f5c\u4e86,\u4ee5\u4e0b\u662f\u6d4b\u8bd5\u4e00\u4e2ademo.py \u6587\u4ef6\u7684\u6253\u5305\uff0c\u6587\u4ef6\u653e\u5728\u5f53\u524d\u76ee\u5f55\u7684pyinstaller-2.1\u6587\u4ef6\u5939\u91cc\u9762 .<br \/>\n<strong>d:\\pyinstaller-2.1&gt;python pyinstaller.py --console --onefile demo.py<\/strong><\/p>\n<p>\u4e0a\u9762\u7684\u547d\u4ee4\u6210\u529f\u8fd0\u884c\u540edemo.py \u4f1a\u751f\u6210\u4e00\u4e2ademo\u6587\u4ef6\u5939\u3002\u5728\u8fd9\u4e2a\u6587\u4ef6\u5939\u4e0b\u9762\u4f1a\u6709\u4e00\u4e2a\u540d\u4e3adist\u7684\u6587\u4ef6\u5939\uff0c\u6b64\u6587\u4ef6\u5939\u4e0b\u9762\u6709\u8f6c\u6362\u597d\u7684demo.exe\u3002<\/p>\n<p><a href=\"https:\/\/www.datarelab.com\/blog\/wp-content\/uploads\/2015\/12\/1.jpg\" rel=\"attachment wp-att-567\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-567\" src=\"https:\/\/www.datarelab.com\/blog\/wp-content\/uploads\/2015\/12\/1.jpg\" alt=\"1\" width=\"840\" height=\"175\" srcset=\"https:\/\/www.datarelab.com\/blog\/wp-content\/uploads\/2015\/12\/1.jpg 840w, https:\/\/www.datarelab.com\/blog\/wp-content\/uploads\/2015\/12\/1-300x63.jpg 300w, https:\/\/www.datarelab.com\/blog\/wp-content\/uploads\/2015\/12\/1-768x160.jpg 768w\" sizes=\"auto, (max-width: 840px) 100vw, 840px\" \/><\/a><\/p>\n<p>\u70b9\u51fb demo.exe\uff0c\u9996\u5148\u4f1a\u51fa\u6765\u4e00\u4e2a \u63a7\u5236\u53f0\u7684\u9ed1\u7a97\u53e3\uff0c\u5982\u4e0b\u56fe\uff1a<\/p>\n<p><a href=\"https:\/\/www.datarelab.com\/blog\/wp-content\/uploads\/2015\/12\/2.jpg\" rel=\"attachment wp-att-568\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-568\" src=\"https:\/\/www.datarelab.com\/blog\/wp-content\/uploads\/2015\/12\/2.jpg\" alt=\"2\" width=\"682\" height=\"160\" srcset=\"https:\/\/www.datarelab.com\/blog\/wp-content\/uploads\/2015\/12\/2.jpg 682w, https:\/\/www.datarelab.com\/blog\/wp-content\/uploads\/2015\/12\/2-300x70.jpg 300w\" sizes=\"auto, (max-width: 682px) 100vw, 682px\" \/><\/a><br \/>\n4, \u4e0a\u9762\u7f16\u8bd1\u51fa\u6765\u7684exe\u80fd\u591f\u6b63\u5e38\u8fd0\u884c\u4e86\uff0c\u4f46\u5e26\u4e00\u4e2a\u9ed1\u8272\u7684console\uff0c\u4ee5\u4e0b\u91cd\u65b0\u7f16\u8bd1\uff0c\u52a0\u5165--windowed --icon\uff0c\u53d6\u6d88--console<br \/>\n<strong>D:\\PyInstaller-2.1&gt;python pyinstaller.py -w --onefile --icon=\"my.ico\" demo.py<\/strong><br \/>\nicon\u662f\u4f60\u559c\u6b22\u7684\u56fe\u6807\u6587\u4ef6\uff0cpy\u4e3a\u4f60\u8981\u6253\u5305\u7684\u7a0b\u5e8f\u3002\u6700\u540e\u751f\u6210\u4e00\u4e2ademo.exe\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u70b9\u51fbdemo.exe\u76f4\u63a5\u663e\u793a\u6240\u7ed8\u56fe\u5f62\u3002<\/p>\n<p><a href=\"https:\/\/www.datarelab.com\/blog\/wp-content\/uploads\/2015\/12\/3.jpg\" rel=\"attachment wp-att-569\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-569\" src=\"https:\/\/www.datarelab.com\/blog\/wp-content\/uploads\/2015\/12\/3.jpg\" alt=\"3\" width=\"602\" height=\"449\" srcset=\"https:\/\/www.datarelab.com\/blog\/wp-content\/uploads\/2015\/12\/3.jpg 602w, https:\/\/www.datarelab.com\/blog\/wp-content\/uploads\/2015\/12\/3-300x224.jpg 300w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6700\u8fd1\u4f7f\u7528Python\u4e3a\u9879\u76ee\u5f00\u53d1\u4e00\u6b3e\u7ed8\u56fe\u5de5\u5177(\u7ed8\u51fa \u58f0\u573a\u4e09\u7ef4\u6a21\u578b)\u3002\u56e0\u4e3a\u5e0c\u671b\u80fd\u628aPython\u811a\u672c\u53d1\u5e03\u4e3a\u8131\u79bbPyt [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[175],"class_list":["post-566","post","type-post","status-publish","format-standard","hentry","category-Technical_literature","tag-python"],"views":1651,"_links":{"self":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts\/566","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/comments?post=566"}],"version-history":[{"count":0,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/posts\/566\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/media?parent=566"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/categories?post=566"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.datarelab.com\/blog\/wp-json\/wp\/v2\/tags?post=566"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}