{"id":18902,"date":"2024-11-19T10:14:31","date_gmt":"2024-11-19T02:14:31","guid":{"rendered":"https:\/\/fwq.ai\/blog\/18902\/"},"modified":"2024-11-19T10:14:31","modified_gmt":"2024-11-19T02:14:31","slug":"%e7%94%a8pyinstaller%e5%b0%86pygame%e8%bd%ac%e4%b8%baexe%e5%b9%b6%e4%b8%8a%e4%bc%a0%e8%87%b3github","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/18902\/","title":{"rendered":"\u7528pyinstaller\u5c06Pygame\u8f6c\u4e3aexe\u5e76\u4e0a\u4f20\u81f3GitHub"},"content":{"rendered":"<p>pygame\u662fpython\u7684\u4e00\u4e2a\u6e38\u620f\u5f00\u53d1\u5e93\uff0c\u5177\u6709\u4e30\u5bcc\u7684\u6e38\u620f\u5f00\u53d1\u529f\u80fd\u3002\u5f00\u53d1\u8005\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u4f7f\u7528pygame\u521b\u5efa\u5404\u79cd\u7c7b\u578b\u7684\u6e38\u620f\uff0c\u4f46\u662f\u5728\u53d1\u5e03\u6e38\u620f\u65f6\u9700\u8981\u5c06pygame\u6e38\u620f\u8f6c\u6362\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff08exe\u6587\u4ef6\uff09\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528pyinstaller\u5c06pygame\u6e38\u620f\u8f6c\u6362\u6210exe\u6587\u4ef6\uff0c\u5e76\u5c06\u5176\u4e0a\u4f20\u81f3github\u3002<\/p>\n<ol>\n<li>\u5b89\u88c5pyinstaller<\/li>\n<\/ol>\n<p>\u9996\u5148\uff0c\u9700\u8981\u5b89\u88c5pyinstaller\u3002Pyinstaller\u662f\u4e00\u4e2a\u5c06Python\u4ee3\u7801\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5de5\u5177\u3002\u4f7f\u7528pip\u547d\u4ee4\u5b89\u88c5pyinstaller\uff1a<\/p>\n<pre>pip install pyinstaller<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li>\u521b\u5efa\u6e38\u620f\u5e76\u6d4b\u8bd5<\/li>\n<\/ol>\n<p>\u5728\u8f6c\u6362\u6e38\u620f\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2aPygame\u6e38\u620f\uff0c\u5e76\u786e\u4fdd\u5b83\u53ef\u4ee5\u5728\u672c\u5730\u673a\u5668\u4e0a\u8fd0\u884c\u3002\u8fd9\u91cc\u63d0\u4f9b\u4e00\u4e2a\u7b80\u5355\u7684Pygame\u6e38\u620f\uff1a<\/p>\n<pre>import pygame\n\npygame.init()\n\nWIDTH, HEIGHT = 640, 480\nscreen = pygame.display.set_mode((WIDTH, HEIGHT))\n\nbackground = pygame.Surface((WIDTH, HEIGHT))\nbackground.fill((255, 255, 255))\n\nwhile True:\n    for event in pygame.event.get():\n        if event.type == pygame.QUIT:\n            pygame.quit()\n            quit()\n\n    screen.blit(background, (0, 0))\n    pygame.display.flip()<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u8fd0\u884c\u6b64\u6e38\u620f\u4e4b\u524d\uff0c\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86Pygame\u3002\u53ea\u9700\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5373\u53ef\u5b89\u88c5Pygame:<\/p>\n<pre>pip install pygame<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5982\u679c\u51fa\u73b0\u95ee\u9898\uff0c\u8bf7\u786e\u4fdd\u5df2\u5728\u6b63\u786e\u7684\u73af\u5883\u4e2d\u5b89\u88c5\u4e86Pygame\u3002<\/p>\n<p>\u5728\u6e38\u620f\u521b\u5efa\u5e76\u8fd0\u884c\u6210\u529f\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5176\u8f6c\u6362\u4e3aexe\u6587\u4ef6\uff0c\u4ee5\u4fbf\u5728\u6ca1\u6709Python\u73af\u5883\u7684\u673a\u5668\u4e0a\u8fd0\u884c\u5b83\u3002<\/p>\n<ol>\n<li>\u5c06Pygame\u6e38\u620f\u8f6c\u6362\u6210exe\u6587\u4ef6<\/li>\n<\/ol>\n<p>\u8981\u5c06Pygame\u6e38\u620f\u8f6c\u6362\u4e3aexe\u6587\u4ef6\uff0c\u9996\u5148\u9700\u8981\u6253\u5f00\u547d\u4ee4\u884c\u7a97\u53e3\uff0c\u5bfc\u822a\u5230\u6e38\u620f\u6240\u5728\u7684\u76ee\u5f55\uff0c\u7136\u540e\u4f7f\u7528pyinstaller\u8f6c\u6362\u5de5\u5177\u6765\u521b\u5efa\u53ef\u6267\u884c\u6587\u4ef6\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre>pyinstaller --onefile --noconsole mygame.py<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u5728\u8fd9\u4e2a\u547d\u4ee4\u4e2d\uff0c\u201c&#8211;onefile\u201d\u548c\u201c&#8211;noconsole\u201d\u9009\u9879\u544a\u8bc9pyinstaller\u5c06\u6240\u6709\u6587\u4ef6\u6253\u5305\u6210\u5355\u4e2a\u6587\u4ef6\uff0c\u4e14\u5e94\u7528\u7a0b\u5e8f\u5c06\u4e0d\u663e\u793a\u63a7\u5236\u53f0\u7a97\u53e3\u3002<\/p>\n<p>\u6267\u884c\u6b64\u547d\u4ee4\u540e\uff0cpyinstaller\u5c06\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u201cdist\u201d\u76ee\u5f55\uff0c\u5e76\u5728\u5176\u4e2d\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<ol>\n<li>\u4e0a\u4f20\u81f3GitHub<\/li>\n<\/ol>\n<p>\u6700\u540e\u4e00\u6b65\u662f\u5c06Pygame\u6e38\u620f\u4e0a\u4f20\u5230GitHub\u4e0a\u3002\u8fd9\u53ef\u4ee5\u901a\u8fc7\u5728GitHub\u4e2d\u521b\u5efa\u65b0\u7684\u5b58\u50a8\u5e93\u6765\u5b8c\u6210\u3002\u521b\u5efa\u4e00\u4e2a\u65b0\u5b58\u50a8\u5e93\u65f6\uff0c\u9700\u8981\u5c06\u5176\u547d\u540d\u4e3a\u6e38\u620f\u7684\u540d\u79f0\uff0c\u5e76\u5728\u201cREADME\u201d\u6587\u4ef6\u4e2d\u63d0\u4f9b\u6709\u5173\u8be5\u6e38\u620f\u7684\u8bf4\u660e\u3002\u5728\u5b8c\u6210\u8fd9\u4e9b\u8bbe\u7f6e\u540e\uff0c\u540c\u6b65\u672c\u5730\u4ee3\u7801\u5230\u65b0\u521b\u5efa\u7684\u8fdc\u7a0b\u5b58\u50a8\u5e93\u4e2d\u3002<\/p>\n<p>\u8fd9\u91cc\u63d0\u4f9b\u4e00\u4e2a\u7b80\u5355\u7684Git\u547d\u4ee4\u5217\u8868\uff1a<\/p>\n<ol>\n<li>git init<\/li>\n<li>git add .<\/li>\n<li>git commit -m &#8220;Initial commit&#8221;<\/li>\n<li>git remote add origin https:\/\/github.com\/{username}\/{repository_name}.git<\/li>\n<li>git push -u origin master<\/li>\n<\/ol>\n<p>\u5728\u6267\u884c\u8fd9\u4e9b\u547d\u4ee4\u4e4b\u540e\uff0c\u6e38\u620f\u5c06\u88ab\u4e0a\u4f20\u5e76\u53ef\u4ee5\u5728GitHub\u4e0a\u8bbf\u95ee\u3002\u5176\u4ed6\u4eba\u53ef\u4ee5\u4ece\u5b58\u50a8\u5e93\u4e2d\u83b7\u53d6\u53ef\u6267\u884c\u6587\u4ef6\u5e76\u5728\u672c\u5730\u8fd0\u884c\u6e38\u620f\u3002<\/p>\n<p>\u603b\u7ed3<\/p>\n<p>\u901a\u8fc7\u8fd9\u7bc7\u6559\u7a0b\uff0c\u60a8\u5e94\u8be5\u5df2\u7ecf\u4e86\u89e3\u4e86\u5982\u4f55\u5c06Pygame\u6e38\u620f\u8f6c\u6362\u4e3aexe\u6587\u4ef6\uff0c\u5e76\u5c06\u5176\u4e0a\u4f20\u5230GitHub\u4e0a\u3002\u5c06\u6e38\u620f\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\u53ef\u4ee5\u4f7f\u6e38\u620f\u5728\u6ca1\u6709Python\u73af\u5883\u7684\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884c\uff0c\u4ece\u800c\u4f7f\u60a8\u7684\u6e38\u620f\u66f4\u6613\u4e8e\u4f20\u64ad\u3002\u540c\u65f6\uff0c\u5c06\u6e38\u620f\u4e0a\u4f20\u5230GitHub\u4e0a\u53ef\u4ee5\u4f7f\u5176\u4ed6\u4eba\u8f7b\u677e\u5730\u8bbf\u95ee\u5e76\u4e0b\u8f7d\u60a8\u7684\u6e38\u620f\uff0c\u5e76\u4fc3\u8fdb\u6e38\u620f\u5f00\u6e90\u793e\u533a\u7684\u53d1\u5c55\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u7528pyinstaller\u5c06Pygame\u8f6c\u4e3aexe\u5e76\u4e0a\u4f20\u81f3GitHub\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>pygame\u662fpython\u7684\u4e00\u4e2a\u6e38\u620f\u5f00\u53d1\u5e93\uff0c\u5177\u6709\u4e30\u5bcc\u7684\u6e38\u620f\u5f00\u53d1\u529f\u80fd\u3002\u5f00\u53d1\u8005\u53ef\u4ee5\u5f88\u65b9\u4fbf\u5730\u4f7f\u7528pygame\u521b\u5efa\u5404\u79cd\u7c7b\u578b\u7684\u6e38\u620f\uff0c\u4f46\u662f\u5728\u53d1\u5e03\u6e38\u620f\u65f6\u9700\u8981\u5c06pygame\u6e38\u620f\u8f6c\u6362\u6210\u53ef\u6267\u884c\u6587\u4ef6\uff08exe\u6587\u4ef6\uff09\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528pyinstaller\u5c06pygame\u6e38\u620f\u8f6c\u6362\u6210exe\u6587\u4ef6\uff0c\u5e76\u5c06\u5176\u4e0a\u4f20\u81f3github\u3002 \u5b89\u88c5pyinstaller \u9996\u5148\uff0c\u9700\u8981\u5b89\u88c5pyinstaller\u3002Pyinstaller\u662f\u4e00\u4e2a\u5c06Python\u4ee3\u7801\u6253\u5305\u6210\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5de5\u5177\u3002\u4f7f\u7528pip\u547d\u4ee4\u5b89\u88c5pyinstaller\uff1a pip install pyinstaller \u767b\u5f55\u540e\u590d\u5236 \u521b\u5efa\u6e38\u620f\u5e76\u6d4b\u8bd5 \u5728\u8f6c\u6362\u6e38\u620f\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u521b\u5efa\u4e00\u4e2aPygame\u6e38\u620f\uff0c\u5e76\u786e\u4fdd\u5b83\u53ef\u4ee5\u5728\u672c\u5730\u673a\u5668\u4e0a\u8fd0\u884c\u3002\u8fd9\u91cc\u63d0\u4f9b\u4e00\u4e2a\u7b80\u5355\u7684Pygame\u6e38\u620f\uff1a import pygame pygame.init() WIDTH, HEIGHT = 640, 480 screen = pygame.display.set_mode((WIDTH, HEIGHT)) background = pygame.Surface((WIDTH, HEIGHT)) background.fill((255, 255, 255)) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() screen.blit(background, (0, 0)) pygame.display.flip() \u767b\u5f55\u540e\u590d\u5236 \u5728\u8fd0\u884c\u6b64\u6e38\u620f\u4e4b\u524d\uff0c\u9700\u8981\u786e\u4fdd\u5df2\u7ecf\u5b89\u88c5\u4e86Pygame\u3002\u53ea\u9700\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5373\u53ef\u5b89\u88c5Pygame: pip install pygame \u767b\u5f55\u540e\u590d\u5236 \u5982\u679c\u51fa\u73b0\u95ee\u9898\uff0c\u8bf7\u786e\u4fdd\u5df2\u5728\u6b63\u786e\u7684\u73af\u5883\u4e2d\u5b89\u88c5\u4e86Pygame\u3002 \u5728\u6e38\u620f\u521b\u5efa\u5e76\u8fd0\u884c\u6210\u529f\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5176\u8f6c\u6362\u4e3aexe\u6587\u4ef6\uff0c\u4ee5\u4fbf\u5728\u6ca1\u6709Python\u73af\u5883\u7684\u673a\u5668\u4e0a\u8fd0\u884c\u5b83\u3002 \u5c06Pygame\u6e38\u620f\u8f6c\u6362\u6210exe\u6587\u4ef6 \u8981\u5c06Pygame\u6e38\u620f\u8f6c\u6362\u4e3aexe\u6587\u4ef6\uff0c\u9996\u5148\u9700\u8981\u6253\u5f00\u547d\u4ee4\u884c\u7a97\u53e3\uff0c\u5bfc\u822a\u5230\u6e38\u620f\u6240\u5728\u7684\u76ee\u5f55\uff0c\u7136\u540e\u4f7f\u7528pyinstaller\u8f6c\u6362\u5de5\u5177\u6765\u521b\u5efa\u53ef\u6267\u884c\u6587\u4ef6\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a pyinstaller [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-18902","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18902","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=18902"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18902\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=18902"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=18902"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=18902"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}