{"id":78,"date":"2020-11-17T09:14:49","date_gmt":"2020-11-17T03:14:49","guid":{"rendered":"http:\/\/www.dreamflier.net\/wordpress\/?p=78"},"modified":"2020-12-17T10:15:41","modified_gmt":"2020-12-17T04:15:41","slug":"python3%e6%89%93%e5%8c%85%e6%88%90exe%e5%8f%af%e6%89%a7%e8%a1%8c%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"http:\/\/www.jichangqing.net\/wordpress\/?p=78","title":{"rendered":"python3\u6253\u5305\u6210exe\u53ef\u6267\u884c\u7a0b\u5e8f"},"content":{"rendered":"<h1 style=\"font-weight: bold;\">\u4f7f\u7528pyinstaller\u5c06python\u6587\u4ef6\u6253\u5305\u6210exe\u7a0b\u5e8f\uff0c\u6253\u5305\u6b65\u9aa4\u5982\u4e0b\uff1a<\/h1>\n<h2 style=\"font-weight: bold;\">\u4e00\u3001\u5b89\u88c5pyinstaller<\/h2>\n<p><strong>(1)win+R\u8f93\u5165cmd\uff0c\u6253\u5f00\u547d\u4ee4\u7a97\u53e3<\/strong><\/p>\n<p><strong>(2)\u5b89\u88c5pyinstaller\uff0c\u5b89\u88c5\u6307\u4ee4\uff1apip install pyinstaller<\/strong><\/p>\n<h2 style=\"font-weight: bold;\">\u4e8c\u3001\u6253\u5305<\/h2>\n<h3 style=\"font-weight: bold;\">1\uff0c\u5207\u6362\u5230\u6253\u5305\u7a0b\u5e8f\u76ee\u5f55<\/h3>\n<p><strong>\u4f8b\uff1a\u9700\u8981\u6253\u5305\u7a0b\u5e8f\u76ee\u5f55\u4e3a\uff1aD:\\automation\\autotest_tool\\interface_param_change_tool<\/strong><\/p>\n<p><strong>\u5207\u6362\u6307\u4ee4\uff1acd D:\\automation\\autotest_tool\\interface_param_change_tool<\/strong><\/p>\n<h3 style=\"font-weight: bold;\">2\uff0c\u6253\u5305\u6587\u4ef6\uff0cpyinstaller -F xxx.py\uff08xxx.py\uff0c\u6253\u5305\u7684\u6587\u4ef6\uff09<\/h3>\n<p><strong>\u4f8b\uff0c\u6253\u5305\u6587\u4ef6\u4e3a\uff1aruner.py,<\/strong><\/p>\n<p><strong> -D \u53c2\u6570\u662f\u751f\u6210\u6240\u6709\u94fe\u63a5\u5e93\u7684\u6587\u4ef6\u5939, -w\u53c2\u6570\u662f\u9690\u85cf\u547d\u4ee4\u884c\u7a97\u53e3(\u5982pygame)<\/strong><\/p>\n<h3 style=\"font-weight: bold;\">3\uff0c\u5230\u6253\u5305\u6587\u4ef6\u76ee\u5f55\u67e5\u770b\u6253\u5305\u597d\u7684\u7a0b\u5e8f\uff0c\u5e76\u6267\u884c<\/h3>\n<p><strong>\uff081\uff09\u6253\u5305\u6210\u529f\u540e\u9879\u76ee\u4e2d\u65b0\u589edist\u6587\u4ef6<\/strong><\/p>\n<p><strong>\uff082\uff09\u8fdb\u5165dist\u6587\u4ef6\uff0c\u70b9\u51fb\u8fd0\u884c\u6253\u5305\u597d\u7684exe\u7a0b\u5e8f<\/strong><\/p>\n<p><strong>\u5982\u679c\u5f15\u7528\u4e86\u56fe\u8c61\u7b49\u8d44\u6e90\u6587\u4ef6\u5939, \u8981\u62f7\u8d1d\u5230\u53d1\u5e03\u76ee\u5f55\u4e0b.\u00a0<\/strong><\/p>\n<p>\u6ce81: \u6267\u884cpyinstaller\u51fa\u9519:<\/p>\n<p>pyinstall : \u65e0\u6cd5\u5c06\u201cpyinstall\u201d\u9879\u8bc6\u522b\u4e3a cmdlet\u3001\u51fd\u6570\u3001\u811a\u672c\u6587\u4ef6\u6216\u53ef\u8fd0\u884c\u7a0b\u5e8f\u7684\u540d\u79f0\u3002\u8bf7\u68c0\u67e5\u540d\u79f0\u7684\u62fc\u5199\uff0c\u5982\u679c\u5305\u62ec\u8def\u5f84\uff0c\u8bf7\u786e\u4fdd\u8def\u5f84\u6b63\u786e\uff0c\u7136\u540e\u518d\u8bd5\u4e00\u6b21\u3002<br \/>\n\u6240\u5728\u4f4d\u7f6e \u884c:1 \u5b57\u7b26: 1<br \/>\n+ pyinstall -F .\\alien_invasion.py<br \/>\n+ ~~~~~~~~~<br \/>\n+ CategoryInfo : ObjectNotFound: (pyinstall:String) [], CommandNotFoundException<br \/>\n+ FullyQualifiedErrorId : CommandNotFoundException<\/p>\n<p>\u6700\u540e\u6709\u4e2a\u8b66\u544a\u8bf4<\/p>\n<p>WARNING: The scripts pyi-archive_viewer.exe, pyi-bindepend.exe, pyi-grab_version.exe, pyi-makespec.exe, pyi-set_version.exe and pyinstaller.exe are installed in &#8216;C:\\Users\\Administrator\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python38\\Scripts&#8217; which is not on PATH.<br \/>\nConsider adding this directory to PATH or, if you prefer to suppress this warning, use &#8211;no-warn-script-location.<br \/>\nSuccessfully installed altgraph-0.17 future-0.18.2 pefile-2019.4.18 pyinstaller-4.0 pyinstaller-hooks-contrib-2020.10 pywin32-ctypes-0.2.0<\/p>\n<p>\u5c31\u662f\u6ca1\u6709\u8bbe\u7f6e\u8be5\u6267\u884c\u76ee\u5f55\u5230\u7cfb\u7edf\u73af\u5883\u53c2\u6570, \u53ef\u4ee5\u8fdb\u5230\u8be5\u76ee\u5f55\u6267\u884cpyinstaller<\/p>\n<p>\u4e3e\u4f8b,\u6267\u884c:<\/p>\n<p>C:\\Users\\Administrator\\AppData\\Local\\Packages\\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\\LocalCache\\local-packages\\Python38\\Scripts\\pyinstaller -F\u00a0 .\\alien_invasion.py<\/p>\n<p>\u6210\u529f.<\/p>\n<p>\u6ce82: \u7ba1\u7406\u5458\u6743\u9650\u8fd0\u884cWindows PowerShell<\/p>\n<p>from:https:\/\/www.cnblogs.com\/mini-monkey\/p\/11195309.html<\/p>\n<p>\u6ce83:\u62a5\u9519\u00a0<span style=\"color: #24292e;\">win32ctypes.pywin32.pywintypes.error\uff1a\uff081920\uff0c\u201c LoadLibraryExW\u201d\uff0c\u201c\u7cfb\u7edf\u65e0\u6cd5\u8bbf\u95ee\u8be5\u6863\u6848\u3002\u201d\uff09<\/span><\/p>\n<p>https:\/\/github.com\/pyinstaller\/pyinstaller\/issues\/4507<\/p>\n<p style=\"color: #24292e;\">\u89e3\u51b3\u65b9\u6cd51\uff1a<\/p>\n<pre style=\"color: #24292e;\"><code># \u7b2c\u4e00\u4e2a\u5730\u65b9\r\n# \u6839\u636e\u9519\u8bef\u4fe1\u606f\u63d0\u793a\u627e\u5230\"win32api.py\"\u6587\u4ef6\r\n# \u4fee\u6539\u5927\u7ea640\u884c\r\ndef LoadLibraryEx(fileName, handle, flags):\r\n    # \u6dfb\u52a0\u8fd9\u4e00\u884c,\u6539\u4e3a\u4f60\u7684python\u8def\u5f84\r\n    fileName = r\"C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.1520.0_x64__qbz5n2kfra8p0\\python.exe\"\r\n    if not handle == 0:\r\n        raise ValueError(\"handle != 0 not supported\")\r\n    with _pywin32error():\r\n        return _dll._LoadLibraryEx(fileName, 0, flags)\r\n\r\n\r\ndef EnumResourceTypes(hModule):\r\n<\/code><\/pre>\n<pre style=\"color: #24292e;\"><code># \u7b2c\u4e8c\u4e2a\u5730\u65b9\r\n# \u4fee\u6539\u5b8c\u7b2c\u4e00\u4e2a\u9519\u8bef\u8fd0\u884c\u4f1a\u62a5\u7b2c\u4e8c\u4e2a\u540c\u6837\u7684\u9519\u8bef\r\n# \u6839\u636e\u9519\u8bef\u63d0\u793a\u4fee\u6539\"pefile.py\"\u6587\u4ef6\r\n# \u4fee\u6539\u5927\u7ea61795\u884c\r\n    def __parse__(self, fname, data, fast_load):\r\n        \"\"\"Parse a Portable Executable file.\r\n\r\n        Loads a PE file, parsing all its structures and making them available\r\n        through the instance's attributes.\r\n        \"\"\"\r\n        # \u6dfb\u52a0\u8fd9\u4e00\u884c,\u540c\u6837\u6539\u4e3a\u4f60\u7684python\u8def\u5f84\r\n        fname = r\"C:\\Program Files\\WindowsApps\\PythonSoftwareFoundation.Python.3.7_3.7.1520.0_x64__qbz5n2kfra8p0\\python.exe\"\r\n        if fname is not None:\r\n            stat = os.stat(fname)\r\n            if stat.st_size == 0:\r\n                raise PEFormatError('The file is empty')\r\n            fd = None<\/code><\/pre>\n<p>\u89e3\u51b3\u65b9\u6cd52\uff1a\u5728\u6a21\u62df\u73af\u5883\u4e0b\u6267\u884c<\/p>\n<p>http:\/\/www.dreamflier.net\/wordpress\/?p=83<\/p>\n<p><span style=\"color: #24292e;\">\u89e3\u51b3\u65b9\u6cd53\uff1a\u4e00\u822c\u662f\u56e0\u4e3a\u76f4\u63a5\u7528\u4e86windows \u5e94\u7528\u5e02\u573a\u5b89\u88c5\u7684python, \u5148\u5728\u5e02\u573a\u4e2d\u5378\u8f7d,\u7136\u540e\u5728\u5b98\u7f51https:\/\/www.python.org\/downloads\/\u4e0b\u8f7d\u5b89\u88c5.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4f7f\u7528pyinstaller\u5c06python\u6587\u4ef6\u6253\u5305\u6210exe\u7a0b\u5e8f\uff0c\u6253\u5305\u6b65\u9aa4\u5982\u4e0b\uff1a \u4e00\u3001\u5b89\u88c5pyinstaller (1)win+R\u8f93\u5165cmd\uff0c\u6253\u5f00\u547d\u4ee4\u7a97\u53e3 (2)\u5b89\u88c5pyinstaller\uff0c\u5b89\u88c5\u6307\u4ee4\uff1apip install pyinstalle &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7,3,4],"tags":[],"class_list":["post-78","post","type-post","status-publish","format-standard","hentry","category-python","category-3","category-4"],"_links":{"self":[{"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/78","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=78"}],"version-history":[{"count":7,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/78\/revisions"}],"predecessor-version":[{"id":89,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/78\/revisions\/89"}],"wp:attachment":[{"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=78"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=78"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.jichangqing.net\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=78"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}