{"id":16859,"date":"2024-02-29T10:43:14","date_gmt":"2024-02-29T02:43:14","guid":{"rendered":"https:\/\/www.yimenyun.cn\/emen\/?p=16859"},"modified":"2024-02-29T10:43:14","modified_gmt":"2024-02-29T02:43:14","slug":"webbrowser%e6%89%93%e5%8c%85exe%e6%93%8d%e4%bd%9c%e5%8a%9e%e6%b3%95%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/www.yimenyun.cn\/emen\/16859\/","title":{"rendered":"webbrowser\u6253\u5305exe\u64cd\u4f5c\u529e\u6cd5\u4ecb\u7ecd"},"content":{"rendered":"

webbrowser\u662fPython\u6807\u51c6\u5e93\u4e2d\u7684\u4e00\u4e2a\u6a21\u5757\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u79cd\u7b80\u5355\u7684\u65b9\u6cd5\u6765\u6253\u5f00\u4e00\u4e2a\u6d4f\u89c8\u5668\u7a97\u53e3\uff0c\u5e76\u5728\u5176\u4e2d\u52a0\u8f7d\u4e00\u4e2a\u6307\u5b9a\u7684URL\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5c06\u4e00\u4e2aPython\u811a\u672c\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u4ee5\u65b9\u4fbf\u7528\u6237\u4f7f\u7528\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528pyinstaller\u5de5\u5177\u5c06\u4e00\u4e2a\u4f7f\u7528webbrowser\u6a21\u5757\u7684Python\u811a\u672c\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n

pyinstaller\u662f\u4e00\u4e2aPython\u7b2c\u4e09\u65b9\u5e93\uff0c\u5b83\u53ef\u4ee5\u5c06Python\u811a\u672c\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002pyinstaller\u53ef\u4ee5\u5728Windows\u3001Linux\u548cMacOS\u7b49\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u4f7f\u7528\uff0c\u652f\u6301\u6253\u5305\u6210\u5355\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3001\u591a\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u4ee5\u53ca\u6253\u5305\u6210\u6587\u4ef6\u5939\u7b49\u591a\u79cd\u65b9\u5f0f\u3002<\/p>\n

\u4e0b\u9762\u6211\u4eec\u5c06\u4ecb\u7ecd\u4f7f\u7528pyinstaller\u5c06\u4e00\u4e2a\u4f7f\u7528webbrowser\u6a21\u5757\u7684Pyth\u8f6f\u4ef6\u6253\u5305\u5de5\u5382<\/a>on\u811a\u672c\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u7684\u6b65\u9aa4\uff1a<\/p>\n

1. \u5b89\u88c5pyinstaller<\/p>\n

\u9996\u5148\u9700\u8981\u5b89\u88c5pyinstaller\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n

“`<\/p>\n

pip install pyinstaller<\/p>\n

“`<\/p>\n

2. \u7f16<\/p>\n

<\/figure>\n<\/p>\n

\u5199Python\u811a\u672c<\/p>\n

\u7f16\u5199\u4e00\u4e2a\u4f7f\u7528webbrowser\u6a21\u5757\u7684Python\u811a\u672c\uff0c\u4f8b\u5982\uff1a<\/p>\n

“`python<\/p>\n

import webbrowser<\/p>\n

url = ‘https:\/\/www.google.com\/’<\/p>\n

webbrowser.open(url)<\/p>\n

“`<\/p>\n

\u8be5\u811a\u672c\u5c06\u4f1a\u5728\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00Google\u7f51\u7ad9\u3002<\/p>\n

3. \u6253\u5305\u53ef\u6267\u884c\u6587\u4ef6<\/p>\n

\u5728\u547d\u4ee4\u884c\u4e2d\u8fdb\u5165\u811a\u672c\u6240\u5728\u7684\u76ee\u5f55\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

pyinstaller –onefile script.py<\/p>\n

“`<\/p>\n

\u5176\u4e2d\uff0cscript.py\u4e3a\u8981\u6253\u5305\u7684Python\u811a\u672c\u7684\u6587\u4ef6\u540d\u3002\u6267\u884c\u8be5\u547d\u4ee4\u540e\uff0cpyinstaller\u5c06\u4f1a\u5728dist\u76ee\u5f55\u4e0b\u751f\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002\u8be5\u53ef\u6267\u884c\u6587\u4ef6\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884c\uff0c\u4f1a\u5728\u6d4f\u89c8\u5668\u4e2d\u6253\u5f00Google\u7f51\u7ad9\u3002<\/p>\n

4. \u6dfb\u52a0\u5176\u4ed6\u6587\u4ef6<\/p>\n

\u5982\u679cPython\u811a\u672c\u4e2d\u4f7f\u7528\u4e86\u5176\u4ed6\u6587\u4ef6\uff0c\u4f8b\u5982\u56fe\u7247\u3001\u6587\u672c\u7b49\uff0c\u9700\u8981\u5c06\u8fd9\u4e9b\u6587\u4ef6\u4e00\u5e76\u6253\u5305\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

pyinstaller –onefile –add-data “image.png;.” script.py<\/p>\n

“`<\/p>\n

\u5176\u4e2d\uff0cimage.png\u4e3a\u8981\u6253\u5305\u7684\u6587\u4ef6\u540d\uff0c”.”\u8868\u793a\u8be5\u6587\u4ef6\u4e0e\u53ef\u6267\u884c\u6587\u4ef6\u5728\u540c\u4e00\u76ee\u5f55\u4e0b\u3002\u53ef\u4ee5\u5c06\u591a\u4e2a\u6587\u4ef6\u4e00\u8d77\u6253\u5305\uff0c\u7528\u5206\u53f7\u9694\u5f00\u3002<\/p>\n

5. \u6253\u5305\u6210\u6587\u4ef6\u5939<\/p>\n

\u5982\u679c\u9700\u8981\u5c06Python\u811a\u672c\u53ca\u5176\u6240\u6709\u4f9d\u8d56\u6587\u4ef6\u6253\u5305\u6210\u4e00\u4e2a\u6587\u4ef6\u5939\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n

“`<\/p>\n

pyinstaller –onedir script.py<\/p>\n

“`<\/p>\n

\u6267\u884c\u8be5\u547d\u4ee4\u540e\uff0cpyinstamac\u5f00\u53d1\u4eba\u5458\u5de5\u5177<\/a>ller\u5c06\u4f1a\u5728dist\u76ee\u5f55\u4e0b\u751f\u6210\u4e00\u4e2a\u6587\u4ef6\u5939\u3002\u8be5\u6587\u4ef6\u5939\u5305\u542b\u53ef\u6267\u884c\u6587\u4ef6\u53ca\u5176\u6240\u6709\u4f9d\u8d56\u6587\u4ef6\u3002<\/p>\n

\u603b\u7ed3<\/p>\n

\u672c\u6587\u4ecb\u7ecd\u4e86\u5982\u4f55\u4f7f\u7528pyinstaller\u5de5\u5177\u5c06\u4e00\u4e2a\u4f7f\u7528webbrowser\u6a21\u5757\u7684Python\u811a\u672c\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002pyinstaller\u662f\u4e00\u4e2a\u7b80\u5355\u6613\u7528\u7684\u6253\u5305\u5de5\u5177\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06Python\u811a\u672c\u6253\u5305\u6210\u5404\u79cd\u5f62\u5f0f\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"

webbrowser\u662fPython\u6807\u51c6\u5e93\u4e2d\u7684\u4e00\u4e2a\u6a21\u5757\uff0c\u5b83\u63d0\u4f9b\u4e86\u4e00\u79cd\u7b80\u5355\u7684\u65b9\u6cd5\u6765\u6253\u5f00\u4e00\u4e2a\u6d4f\u89c8\u5668\u7a97\u53e3\uff0c\u5e76\u5728\u5176\u4e2d\u52a0\u8f7d\u4e00\u4e2a\u6307\u5b9a\u7684URL\u3002\u5728\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c\u6211\u4eec\u53ef\u80fd\u9700\u8981\u5c06\u4e00\u4e2aPython\u811a\u672c\u6253\u5305\u6210\u4e00\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\uff0c<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[20010,20009,256,832,408],"topic":[],"class_list":["post-16859","post","type-post","status-publish","format-standard","hentry","category-exekf","tag-uewindows","tag-win","tag-256","tag-832","tag-408"],"_links":{"self":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/16859","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/comments?post=16859"}],"version-history":[{"count":1,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/16859\/revisions"}],"predecessor-version":[{"id":16888,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/posts\/16859\/revisions\/16888"}],"wp:attachment":[{"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/media?parent=16859"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/categories?post=16859"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/tags?post=16859"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.yimenyun.cn\/emen\/wp-json\/wp\/v2\/topic?post=16859"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}