{"id":740,"date":"2023-05-27T10:36:57","date_gmt":"2023-05-27T02:36:57","guid":{"rendered":"http:\/\/xinyixx.com\/?p=740"},"modified":"2023-05-27T11:13:57","modified_gmt":"2023-05-27T03:13:57","slug":"python1","status":"publish","type":"post","link":"https:\/\/www.xinyixx.com\/index.php\/2023\/05\/27\/python1\/","title":{"rendered":"\u6559\u5927\u5bb6\u5199\u4e00\u4e2apython\u7684\u4ea4\u4e92\u5f0f.exe\u7a0b\u5e8f"},"content":{"rendered":"<p>\u8fd9\u4e2a\u7a0b\u5e8f\u7528\u5230\u7684\u662fpython\u4e0amatplotlib\u6a21\u5757\u3002<\/p>\n\n\n\n<p>Matplotlib\u662f\u4e00\u4e2a\u7528\u4e8e\u7ed8\u5236\u6570\u636e\u53ef\u89c6\u5316\u56fe\u8868\u7684Python\u5e93\u3002\u5b83\u53ef\u4ee5\u521b\u5efa\u5404\u79cd\u7c7b\u578b\u7684\u56fe\u8868\uff0c\u5305\u62ec\u6298\u7ebf\u56fe\u3001\u6563\u70b9\u56fe\u3001\u67f1\u72b6\u56fe\u3001\u997c\u56fe\u3001\u7b49\u9ad8\u7ebf\u56fe\u7b49\u3002Matplotlib\u5177\u6709\u5e7f\u6cdb\u7684\u529f\u80fd\u548c\u7075\u6d3b\u6027\uff0c\u53ef\u4ee5\u6ee1\u8db3\u5404\u79cd\u7ed8\u56fe\u9700\u6c42\u3002<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u662fMatplotlib\u7684\u4e00\u4e9b\u4e3b\u8981\u7279\u70b9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u7075\u6d3b\u6027\uff1aMatplotlib\u652f\u6301\u591a\u79cd\u7ed8\u56fe\u98ce\u683c\uff0c\u53ef\u4ee5\u521b\u5efa\u5404\u79cd\u7c7b\u578b\u7684\u56fe\u8868\uff0c\u5e76\u5141\u8bb8\u7528\u6237\u81ea\u5b9a\u4e49\u6bcf\u4e2a\u5143\u7d20\u7684\u5916\u89c2\u548c\u5c5e\u6027\u3002<\/li>\n\n\n\n<li>\u6613\u4e8e\u4f7f\u7528\uff1aMatplotlib\u5177\u6709\u7b80\u5355\u6613\u61c2\u7684API\uff0c\u4f7f\u5f97\u7528\u6237\u53ef\u4ee5\u8f7b\u677e\u5730\u521b\u5efa\u548c\u5b9a\u5236\u56fe\u8868\u3002<\/li>\n\n\n\n<li>\u4ea4\u4e92\u5f0f\u7ed8\u56fe\uff1aMatplotlib\u652f\u6301\u4ea4\u4e92\u5f0f\u7ed8\u56fe\uff0c\u7528\u6237\u53ef\u4ee5\u901a\u8fc7\u7f29\u653e\u3001\u5e73\u79fb\u548c\u65cb\u8f6c\u7b49\u64cd\u4f5c\u6765\u63a2\u7d22\u6570\u636e\u3002<\/li>\n\n\n\n<li>\u591a\u5e73\u53f0\u652f\u6301\uff1aMatplotlib\u53ef\u4ee5\u5728\u591a\u4e2a\u64cd\u4f5c\u7cfb\u7edf\u4e0a\u8fd0\u884c\uff0c\u5e76\u4e14\u53ef\u4ee5\u4e0e\u8bb8\u591aGUI\u5de5\u5177\u5305\uff08\u5982Tkinter\u3001wxPython\u548cQt\uff09\u96c6\u6210\u3002<\/li>\n<\/ul>\n\n\n\n<!--more-->\n\n\n\n<p>Matplotlib\u4e3b\u8981\u7531\u4ee5\u4e0b\u51e0\u4e2a\u6a21\u5757\u7ec4\u6210\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>pyplot\uff1a\u8fd9\u662fMatplotlib\u7684\u4e3b\u8981\u6a21\u5757\uff0c\u5b83\u63d0\u4f9b\u4e86\u7c7b\u4f3c\u4e8eMATLAB\u7684\u754c\u9762\uff0c\u4f7f\u5f97\u7528\u6237\u53ef\u4ee5\u8f7b\u677e\u5730\u521b\u5efa\u548c\u5b9a\u5236\u56fe\u8868\u3002<\/li>\n\n\n\n<li>pylab\uff1a\u8fd9\u662f\u4e00\u4e2a\u4fbf\u5229\u7684\u6a21\u5757\uff0c\u5b83\u5c06pyplot\u548cNumPy\u7b49\u5e93\u7ec4\u5408\u5728\u4e00\u8d77\uff0c\u5e76\u63d0\u4f9b\u4e86\u4e00\u4e9b\u989d\u5916\u7684\u529f\u80fd\u3002<\/li>\n\n\n\n<li>artist\uff1a\u8fd9\u662fMatplotlib\u4e2d\u6240\u6709\u53ef\u89c1\u5143\u7d20\uff08\u5982\u56fe\u5f62\u3001\u8f74\u3001\u6587\u672c\u7b49\uff09\u7684\u57fa\u7c7b\u3002<\/li>\n\n\n\n<li>backend\uff1a\u8fd9\u662fMatplotlib\u7684\u540e\u7aef\u6a21\u5757\uff0c\u5b83\u8d1f\u8d23\u5c06\u56fe\u5f62\u6e32\u67d3\u5230\u5c4f\u5e55\u6216\u6587\u4ef6\u4e2d\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u4e0b\u9762\u5f00\u59cb\u53bb\u5982\u4f55\u7528pycharm\u5b9e\u73b0\u8fd9\u4e2a\u53ef\u6267\u884c\u7a0b\u5e8f\u3002<\/p>\n\n\n\n<p>\u9996\u5148\u4e0b\u8f7d\u4e00\u4e2apycharm\u7a0b\u5e8f\uff0c\u5b98\u7f51\u4e0b\u8f7d\u5730\u5740\uff1a<a href=\"https:\/\/www.jetbrains.com\/pycharm\/download\/\" target=\"_blank\" rel=\"noopener\" title=\"\u70b9\u8fd9\u91cc\">\u70b9\u8fd9\u91cc<\/a><\/p>\n\n\n\n<p>\u5b89\u88c5\u540e\uff0c\u5de6\u4e0a\u89d2\u6587\u4ef6-\u65b0\u5efa\u9879\u76ee<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><noscript><img decoding=\"async\" src=\"http:\/\/xinyixx.com\/wp-content\/uploads\/2023\/05\/image-5.png\" alt class=\"wp-image-746\" width=\"674\" height=\"543\" srcset=\"https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-5.png 816w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-5-300x242.png 300w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-5-768x619.png 768w\" sizes=\"(max-width: 674px) 100vw, 674px\"><\/noscript><img decoding=\"async\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20674%20543%22%3E%3C%2Fsvg%3E\" alt class=\"wp-image-746 lazyload\" width=\"674\" height=\"543\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20674%20543%22%3E%3C%2Fsvg%3E 674w\" sizes=\"(max-width: 674px) 100vw, 674px\" data-srcset=\"https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-5.png 816w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-5-300x242.png 300w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-5-768x619.png 768w\" data-src=\"http:\/\/xinyixx.com\/wp-content\/uploads\/2023\/05\/image-5.png\"><\/figure>\n\n\n\n<p>\u9ed8\u8ba4\u8bbe\u7f6e\u5373\u53ef\u3002<\/p>\n\n\n\n<p>\u53f3\u952e\u70b9\u51fb\u8be5\u5de5\u7a0b\uff0c\u65b0\u5efa\u4e00\u4e2apython\u6587\u4ef6\uff0c\u9700\u8981\u5728\u8fd9\u4e2a\u6587\u4ef6\u91cc\u5bfc\u5165\u6a21\u5757\uff0c\u8fd9\u91cc\u7528\u5230\u7684\u6a21\u5757\u5c31\u662fMatplotlib numpy\uff0c\u770b\u6700\u4e0b\u9762\uff0c\u9009\u7ec8\u7aef\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"552\" height=\"48\" src=\"http:\/\/xinyixx.com\/wp-content\/uploads\/2023\/05\/image-6.png\" alt class=\"wp-image-747\" srcset=\"https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-6.png 552w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-6-300x26.png 300w\" sizes=\"(max-width: 552px) 100vw, 552px\"><\/noscript><img decoding=\"async\" width=\"552\" height=\"48\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20552%2048%22%3E%3C%2Fsvg%3E\" alt class=\"wp-image-747 lazyload\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20552%2048%22%3E%3C%2Fsvg%3E 552w\" sizes=\"(max-width: 552px) 100vw, 552px\" data-srcset=\"https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-6.png 552w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-6-300x26.png 300w\" data-src=\"http:\/\/xinyixx.com\/wp-content\/uploads\/2023\/05\/image-6.png\"><\/figure>\n\n\n\n<p>\u9700\u8981\u5728\u7ec8\u7aef\u5185\u7528\u547d\u4ee4\uff1apip install matplotlib numpy<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><noscript><img decoding=\"async\" width=\"1024\" height=\"217\" src=\"http:\/\/xinyixx.com\/wp-content\/uploads\/2023\/05\/image-7-1024x217.png\" alt class=\"wp-image-748\" srcset=\"https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-7-1024x217.png 1024w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-7-300x64.png 300w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-7-768x163.png 768w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-7.png 1293w\" sizes=\"(max-width: 1024px) 100vw, 1024px\"><\/noscript><img decoding=\"async\" width=\"1024\" height=\"217\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201024%20217%22%3E%3C%2Fsvg%3E\" alt class=\"wp-image-748 lazyload\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201024%20217%22%3E%3C%2Fsvg%3E 1024w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" data-srcset=\"https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-7-1024x217.png 1024w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-7-300x64.png 300w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-7-768x163.png 768w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-7.png 1293w\" data-src=\"http:\/\/xinyixx.com\/wp-content\/uploads\/2023\/05\/image-7-1024x217.png\"><\/figure>\n\n\n\n<p>\u5b89\u88c5\u5b8c\u6bd5\uff0c\u5c31\u53ef\u4ee5\u5728python\u6587\u4ef6\u5199\u4ee3\u7801\u4e86<\/p>\n\n\n\n<p>\u4e0b\u9762\u662f\u8fd9\u4e2a\u7a0b\u5e8f\u6e90\u7801\uff1a\uff08\u51fd\u6570\u548c\u529f\u80fd\u5df2\u6ce8\u91ca\u4e86\uff0c\u590d\u5236\u8fdb\u53bb\u5c31\u53ef\u4ee5\uff09<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-cyan-blue-color\">import time\n\nimport numpy as np\n\nimport matplotlib.pyplot as plt\n\n#\u5199\u5165\u6587\u5b57\u9700\u8981\u5b58\u5728\u6c49\u5b57\u5305\u7684\u5b57\u4f53\u6587\u4ef6\nplt.rcParams['font.family'] = 'Arial Unicode MS'\n\ndef tellme(s):\n    print(s)\n    plt.title(s, fontsize=16)\n    plt.draw()\n\nplt.figure()\nplt.xlim(0, 1)#\u5750\u6807\u7cfbx\u663e\u793a\u9650\u5236\nplt.ylim(0, 1)#\u5750\u6807\u7cfby\u663e\u793a\u9650\u5236\n\ntellme('\u4f60\u5c06\u5b9a\u4e49\u4e00\u4e2a\u4e09\u89d2\u5f62\uff0c\u70b9\u51fb\u5f00\u59cb')\n\n#waitforbuttonpress \u4fa6\u542c\u6309\u952e\u51fd\u6570\nplt.waitforbuttonpress()\n\nwhile True:\n    pts = []\n    while len(pts) &lt; 3:\n        tellme('\u7528\u9f20\u6807\u9009\u62e93\u4e2a\u89d2')\n        pts = np.asarray(plt.ginput(3, timeout=-1))#np.asarray \u7528\u4e8e\u5c06\u8f93\u5165\u8f6c\u6362\u4e3a\u6570\u7ec4\u7684\u51fd\u6570\n        if len(pts) &lt; 3:\n            tellme('\u70b9\u592a\u5c11\uff0c\u91cd\u65b0\u5f00\u59cb')\n            time.sleep(1)  # \u7b491\u79d2\n\n    ph = plt.fill(pts[:, 0], pts[:, 1], 'r', lw=2)\n\n    tellme('\u6210\u529f\u4e86\u5417\uff1f\u952e\u76d8\u70b9\u51fb\u8868\u793a\u662f\uff0c\u9f20\u6807\u70b9\u51fb\u8868\u793a\u4e0d\u662f')\n\n    if plt.waitforbuttonpress():<code>\n        break\n\n    # \u6446\u8131\u586b\u5145\n    for p in ph:\n        p.remove()\n\n# \u5b9a\u4e49\u4e00\u4e2a\u4e0e\u5404\u4e2a\u70b9\u7684\u8ddd\u79bb\u7684\u51fd\u6570\ndef f(x, y, pts):\n    z = np.zeros_like(x)\n    for p in pts:\n        z = z + 1\/(np.sqrt((x - p[0])**2 + (y - p[1])**2))\n    return 1\/z\n\n#np.meshgrid \u7528\u4e8e\u751f\u6210\u7f51\u683c\u70b9\u5750\u6807\u77e9\u9635\u7684\u51fd\u6570\uff0c\u901a\u5e38\u7528\u4e8e\u5728\u4e8c\u7ef4\u6216\u4e09\u7ef4\u7a7a\u95f4\u4e2d\u7ed8\u5236\u51fd\u6570\u56fe\u50cf\u6216\u8fdb\u884c\u63d2\u503c\u8fd0\u7b97\n\nX, Y = np.meshgrid(np.linspace(-1, 1, 51), np.linspace(-1, 1, 51))\nZ = f(X, Y, pts)\n\nCS = plt.contour(X, Y, Z, 20)\n\ntellme('\u7528\u9f20\u6807\u9009\u62e9\u7b49\u9ad8\u7ebf\u6807\u7b7e\u4f4d\u7f6e\uff0c\u4e2d\u952e\u5b8c\u6210')\nCL = plt.clabel(CS, manual=True)\n\ntellme('\u73b0\u5728\u505a\u4e00\u4e2a\u5d4c\u5957\u7f29\u653e\uff0c\u70b9\u51fb\u5f00\u59cb')\nplt.waitforbuttonpress()\n\nwhile True:\n    tellme('\u9009\u62e9\u7f29\u653e\u7684\u4e24\u4e2a\u89d2\uff0c\u9f20\u6807\u4e2d\u952e\u5b8c\u6210')\n    pts = plt.ginput(2, timeout=-1)\n    if len(pts) &lt; 2:\n        break\n    (x0, y0), (x1, y1) = pts\n    xmin, xmax = sorted([x0, x1])\n    ymin, ymax = sorted([y0, y1])\n    plt.xlim(xmin, xmax)\n    plt.ylim(ymin, ymax)\n\ntellme('\u5b8c\u6210!')\nplt.show()<\/code><\/mark><\/pre>\n\n\n\n<p>\u6211\u4eec\u5728pycharm\u73af\u5883\u4e2d\u6d4b\u8bd5\u4e00\u4e0b\uff08ctrl+shift+F10\uff0c\u6d4b\u8bd5\u5f53\u524d\u4ee3\u7801\u6267\u884c\uff09<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><noscript><img decoding=\"async\" width=\"1024\" height=\"613\" src=\"http:\/\/xinyixx.com\/wp-content\/uploads\/2023\/05\/image-1024x613.png\" alt class=\"wp-image-741\" srcset=\"https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-1024x613.png 1024w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-300x179.png 300w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-768x459.png 768w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image.png 1506w\" sizes=\"(max-width: 1024px) 100vw, 1024px\"><\/noscript><img decoding=\"async\" width=\"1024\" height=\"613\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201024%20613%22%3E%3C%2Fsvg%3E\" alt class=\"wp-image-741 lazyload\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201024%20613%22%3E%3C%2Fsvg%3E 1024w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" data-srcset=\"https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-1024x613.png 1024w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-300x179.png 300w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-768x459.png 768w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image.png 1506w\" data-src=\"http:\/\/xinyixx.com\/wp-content\/uploads\/2023\/05\/image-1024x613.png\"><\/figure>\n\n\n\n<p>\u8fd0\u884c\u6ca1\u5565\u95ee\u9898\uff0c\u90093\u4e2a\u89d2\uff0c\u751f\u6210\u7b49\u9ad8\u7ebf<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"640\" height=\"480\" src=\"http:\/\/xinyixx.com\/wp-content\/uploads\/2023\/05\/image-1.png\" alt class=\"wp-image-742\" srcset=\"https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-1.png 640w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-1-300x225.png 300w\" sizes=\"(max-width: 640px) 100vw, 640px\"><\/noscript><img decoding=\"async\" width=\"640\" height=\"480\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20640%20480%22%3E%3C%2Fsvg%3E\" alt class=\"wp-image-742 lazyload\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20640%20480%22%3E%3C%2Fsvg%3E 640w\" sizes=\"(max-width: 640px) 100vw, 640px\" data-srcset=\"https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-1.png 640w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-1-300x225.png 300w\" data-src=\"http:\/\/xinyixx.com\/wp-content\/uploads\/2023\/05\/image-1.png\"><\/figure>\n\n\n\n<p>\u9009\u62e9\u7f29\u653e\u4e24\u4e2a\u89d2\uff0c\u6309\u9f20\u6807\u4e2d\u952e\u5b8c\u6210<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"640\" height=\"480\" src=\"http:\/\/xinyixx.com\/wp-content\/uploads\/2023\/05\/image-2.png\" alt class=\"wp-image-743\" srcset=\"https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-2.png 640w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-2-300x225.png 300w\" sizes=\"(max-width: 640px) 100vw, 640px\"><\/noscript><img decoding=\"async\" width=\"640\" height=\"480\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20640%20480%22%3E%3C%2Fsvg%3E\" alt class=\"wp-image-743 lazyload\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20640%20480%22%3E%3C%2Fsvg%3E 640w\" sizes=\"(max-width: 640px) 100vw, 640px\" data-srcset=\"https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-2.png 640w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-2-300x225.png 300w\" data-src=\"http:\/\/xinyixx.com\/wp-content\/uploads\/2023\/05\/image-2.png\"><\/figure>\n\n\n\n<p>\u7528pyinstaller\u5c01\u88c5py\u4ee3\u7801\uff0c\u751f\u6210\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n\n\n\n<p>\u5148\u5728\u7ec8\u7aef\u91ccpip install pyinstaller<\/p>\n\n\n\n<p>\u5728windows\u7684cmd\u627e\u5230pyinstaller\u6267\u884c\u5199\u7684\u4ee3\u7801\uff0c\u5728\u5176\u76ee\u5f55\u4f1a\u751f\u6210dist\u6587\u4ef6\u5939\uff0c\u91cc\u9762\u5c31\u662fwindows\u7684\u53ef\u6267\u884c\u6587\u4ef6<\/p>\n\n\n\n<p>\u5982\u679c\u5728\u8fd0\u884c <code>pyinstaller<\/code> \u547d\u4ee4\u65f6\u51fa\u73b0 <mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\"><code>'pyinstaller' \u4e0d\u662f\u5185\u90e8\u6216\u5916\u90e8\u547d\u4ee4<\/code> <\/mark>\u7684\u9519\u8bef\uff0c\u53ef\u80fd\u662f\u56e0\u4e3a <code>pyinstaller<\/code> \u6ca1\u6709\u6b63\u786e\u5b89\u88c5\u6216\u8005\u6ca1\u6709\u6dfb\u52a0\u5230\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u4e2d\u3002<\/p>\n\n\n\n<p>\u53ef\u4ee5\u5c1d\u8bd5\u4ee5\u4e0b\u89e3\u51b3\u65b9\u6cd5\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5982\u679c\u5c1a\u672a\u5b89\u88c5 <code>pyinstaller<\/code>\uff0c\u8bf7\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\uff1a\u590d\u5236<code>pip install pyinstaller<\/code>\uff08\u5176\u5b9e\u5df2\u7ecf\u5728\u4e0a\u9762\u88c5\u4e86\uff0c\u53ea\u662f\u4e0d\u5728\u73af\u5883\u53d8\u91cf\u91cc\uff09<\/li>\n\n\n\n<li>\u5982\u679c\u5df2\u7ecf\u5b89\u88c5\u4e86 <code>pyinstaller<\/code>\uff0c\u8bf7\u68c0\u67e5\u662f\u5426\u5c06\u5176\u6dfb\u52a0\u5230\u4e86\u7cfb\u7edf\u73af\u5883\u53d8\u91cf\u4e2d\u3002\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u8fdb\u884c\u64cd\u4f5c\uff1a\n<ul class=\"wp-block-list\">\n<li>\u53f3\u952e\u5355\u51fb\u201c\u6b64\u7535\u8111\u201d\u5e76\u9009\u62e9\u201c\u5c5e\u6027\u201d\u3002<\/li>\n\n\n\n<li>\u9009\u62e9\u201c\u9ad8\u7ea7\u7cfb\u7edf\u8bbe\u7f6e\u201d\u3002<\/li>\n\n\n\n<li>\u5728\u201c\u9ad8\u7ea7\u201d\u9009\u9879\u5361\u4e0b\uff0c\u5355\u51fb\u201c\u73af\u5883\u53d8\u91cf\u201d\u3002<\/li>\n\n\n\n<li>\u5728\u201c\u7cfb\u7edf\u53d8\u91cf\u201d\u4e0b\u627e\u5230\u201cPath\u201d\uff0c\u5e76\u5355\u51fb\u201c\u7f16\u8f91\u201d\u3002<\/li>\n\n\n\n<li>\u5728\u5f39\u51fa\u7684\u5bf9\u8bdd\u6846\u4e2d\uff0c\u5355\u51fb\u201c\u65b0\u5efa\u201d\uff0c\u5e76\u8f93\u5165&nbsp;<code>C:\\PythonXX\\Scripts<\/code>\uff08\u5176\u4e2d&nbsp;<code>XX<\/code>&nbsp;\u662f\u60a8\u7684Python\u7248\u672c\u53f7\uff09\u3002<\/li>\n\n\n\n<li>\u5355\u51fb\u201c\u786e\u5b9a\u201d\u4fdd\u5b58\u66f4\u6539\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u5982\u4f55\u8fd8\u4e0d\u884c\uff0c\u76f4\u63a5cd\u5230\u8be5\u5de5\u7a0b\u7684\u76ee\u5f55\u4e0b\\venv\\scripts\\\u521a\u624d\u88c5\u7684installer\u5728\u8fd9\u91cc\u9762\uff0c\u5982\u4e0b\u56fe\u6240\u793a<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><noscript><img decoding=\"async\" width=\"1024\" height=\"549\" src=\"http:\/\/xinyixx.com\/wp-content\/uploads\/2023\/05\/image-3-1024x549.png\" alt class=\"wp-image-744\" srcset=\"https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-3-1024x549.png 1024w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-3-300x161.png 300w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-3-768x412.png 768w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-3.png 1225w\" sizes=\"(max-width: 1024px) 100vw, 1024px\"><\/noscript><img decoding=\"async\" width=\"1024\" height=\"549\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201024%20549%22%3E%3C%2Fsvg%3E\" alt class=\"wp-image-744 lazyload\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201024%20549%22%3E%3C%2Fsvg%3E 1024w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" data-srcset=\"https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-3-1024x549.png 1024w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-3-300x161.png 300w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-3-768x412.png 768w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-3.png 1225w\" data-src=\"http:\/\/xinyixx.com\/wp-content\/uploads\/2023\/05\/image-3-1024x549.png\"><\/figure>\n\n\n\n<p>\u597d\u4e86\u770b\u4e00\u4e0bdist\u7684\u6587\u4ef6\u5427\uff0c<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><noscript><img decoding=\"async\" width=\"646\" height=\"819\" src=\"http:\/\/xinyixx.com\/wp-content\/uploads\/2023\/05\/image-8.png\" alt class=\"wp-image-749\" srcset=\"https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-8.png 646w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-8-237x300.png 237w\" sizes=\"(max-width: 646px) 100vw, 646px\"><\/noscript><img decoding=\"async\" width=\"646\" height=\"819\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20646%20819%22%3E%3C%2Fsvg%3E\" alt class=\"wp-image-749 lazyload\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%20646%20819%22%3E%3C%2Fsvg%3E 646w\" sizes=\"(max-width: 646px) 100vw, 646px\" data-srcset=\"https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-8.png 646w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-8-237x300.png 237w\" data-src=\"http:\/\/xinyixx.com\/wp-content\/uploads\/2023\/05\/image-8.png\"><\/figure>\n\n\n\n<p>\u5230\u8fd9\u4e00\u6b65\u4f60\u5c31\u7528\u6709\u81ea\u5df1\u7684\u7b2c\u4e00\u4e2a.exe\u7a0b\u5e8f\u4e86\uff0c\u5927\u529f\u544a\u6210\uff01<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><noscript><img decoding=\"async\" width=\"1024\" height=\"492\" src=\"http:\/\/xinyixx.com\/wp-content\/uploads\/2023\/05\/image-9-1024x492.png\" alt class=\"wp-image-758\" srcset=\"https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-9-1024x492.png 1024w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-9-300x144.png 300w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-9-768x369.png 768w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-9-1536x739.png 1536w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-9.png 1626w\" sizes=\"(max-width: 1024px) 100vw, 1024px\"><\/noscript><img decoding=\"async\" width=\"1024\" height=\"492\" src=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201024%20492%22%3E%3C%2Fsvg%3E\" alt class=\"wp-image-758 lazyload\" srcset=\"data:image\/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20viewBox%3D%220%200%201024%20492%22%3E%3C%2Fsvg%3E 1024w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" data-srcset=\"https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-9-1024x492.png 1024w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-9-300x144.png 300w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-9-768x369.png 768w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-9-1536x739.png 1536w, https:\/\/www.xinyixx.com\/wp-content\/uploads\/2023\/05\/image-9.png 1626w\" data-src=\"http:\/\/xinyixx.com\/wp-content\/uploads\/2023\/05\/image-9-1024x492.png\"><\/figure>\n\n\n\n<p>\u6709\u5404\u8def\u5927\u795e\u6765\u8bbf\u95ee\u8fd9\u7f51\u7ad9\uff0c\u6211\u5c31\u4e0d\u7559\u540e\u95e8\u5566\u3002\u9700\u8981exe\u6587\u4ef6\u7684\u53ef\u4ee5\u7559\u8a00\u6216\u8005\u8054\u7cfb\u6211\u3002zhizhonggzz@gmail.com<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8fd9\u4e2a\u7a0b\u5e8f\u7528\u5230\u7684\u662fpython\u4e0amatplotlib\u6a21\u5757\u3002 Matplotlib\u662f\u4e00\u4e2a\u7528\u4e8e\u7ed8\u5236\u6570\u636e\u53ef\u89c6\u5316\u56fe\u8868\u7684P [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[14,10,7],"tags":[78,71,79,77],"class_list":["post-740","post","type-post","status-publish","format-standard","hentry","category-teacher","category-coding","category-software","tag-matplotlib","tag-python","tag-code","tag-coding","entry"],"_links":{"self":[{"href":"https:\/\/www.xinyixx.com\/index.php\/wp-json\/wp\/v2\/posts\/740","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xinyixx.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xinyixx.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xinyixx.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xinyixx.com\/index.php\/wp-json\/wp\/v2\/comments?post=740"}],"version-history":[{"count":0,"href":"https:\/\/www.xinyixx.com\/index.php\/wp-json\/wp\/v2\/posts\/740\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.xinyixx.com\/index.php\/wp-json\/wp\/v2\/media?parent=740"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xinyixx.com\/index.php\/wp-json\/wp\/v2\/categories?post=740"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xinyixx.com\/index.php\/wp-json\/wp\/v2\/tags?post=740"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}