{"id":1066904,"date":"2024-12-31T16:30:23","date_gmt":"2024-12-31T08:30:23","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1066904.html"},"modified":"2024-12-31T16:30:26","modified_gmt":"2024-12-31T08:30:26","slug":"%e6%b2%a1%e6%9c%89%e5%ae%89%e8%a3%85python%e7%9a%84%e7%94%b5%e8%84%91%e5%a6%82%e4%bd%95%e8%bf%90%e8%a1%8c-py","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1066904.html","title":{"rendered":"\u6ca1\u6709\u5b89\u88c5python\u7684\u7535\u8111\u5982\u4f55\u8fd0\u884c.py"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-docs.pingcode.com\/wp-content\/uploads\/2024\/12\/42bf2e44-26ad-4363-bae9-33afda7b6c5f.webp?x-oss-process=image\/auto-orient,1\/format,webp\" alt=\"\u6ca1\u6709\u5b89\u88c5python\u7684\u7535\u8111\u5982\u4f55\u8fd0\u884c.py\" \/><\/p>\n<p><p> \u5728\u6ca1\u6709\u5b89\u88c5Python\u7684\u7535\u8111\u4e0a\u8fd0\u884c.py\u6587\u4ef6\u786e\u5b9e\u662f\u4e00\u4e2a\u6311\u6218\uff0c\u4f46\u662f\u6709\u4e00\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u5e2e\u52a9\u60a8\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u3002<strong>\u4f7f\u7528\u4fbf\u643a\u7248\u672c\u7684Python\u3001\u4f7f\u7528\u5728\u7ebfPython\u7f16\u8bd1\u5668\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u5de5\u5177\u5c06.py\u6587\u4ef6\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u6587\u4ef6<\/strong>\uff0c\u8fd9\u4e9b\u65b9\u6cd5\u90fd\u53ef\u4ee5\u6709\u6548\u5730\u89e3\u51b3\u95ee\u9898\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u4fbf\u643a\u7248\u672c\u7684Python<\/h3>\n<\/p>\n<p><p>\u4fbf\u643a\u7248\u672c\u7684Python\uff08Portable Python\uff09\u662f\u4e00\u79cd\u4e0d\u9700\u8981\u5b89\u88c5\u7684Python\u7248\u672c\uff0c\u53ef\u4ee5\u76f4\u63a5\u5728U\u76d8\u6216\u5176\u4ed6\u5916\u90e8\u5b58\u50a8\u8bbe\u5907\u4e0a\u8fd0\u884c\u3002\u8fd9\u6837\u5373\u4f7f\u7535\u8111\u4e0a\u6ca1\u6709\u5b89\u88c5Python\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7\u4fbf\u643a\u7248\u672c\u6765\u8fd0\u884c.py\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>1. \u4e0b\u8f7d\u4fbf\u643a\u7248\u672c\u7684Python<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u4ece\u4e92\u8054\u7f51\u4e0b\u8f7d\u4fbf\u643a\u7248\u672c\u7684Python\u3002\u6709\u5f88\u591a\u7f51\u7ad9\u63d0\u4f9b\u8fd9\u79cd\u7248\u672c\uff0c\u5982WinPython\u3001Portable Python\u7b49\u3002\u786e\u4fdd\u4e0b\u8f7d\u4e0e\u60a8\u7684\u64cd\u4f5c\u7cfb\u7edf\u517c\u5bb9\u7684\u7248\u672c\u3002<\/p>\n<\/p>\n<p><h4>2. \u89e3\u538b\u548c\u914d\u7f6e<\/h4>\n<\/p>\n<p><p>\u4e0b\u8f7d\u5b8c\u6210\u540e\uff0c\u89e3\u538b\u7f29\u6587\u4ef6\u5230U\u76d8\u6216\u5176\u4ed6\u5916\u90e8\u5b58\u50a8\u8bbe\u5907\u3002\u89e3\u538b\u540e\uff0c\u60a8\u4f1a\u770b\u5230\u4e00\u4e2a\u7c7b\u4f3c\u4e8e\u5b89\u88c5\u4e86Python\u7684\u76ee\u5f55\u7ed3\u6784\uff0c\u5305\u62ecbin\u3001lib\u7b49\u6587\u4ef6\u5939\u3002<\/p>\n<\/p>\n<p><h4>3. \u8fd0\u884c.py\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u8fdb\u5165\u89e3\u538b\u540e\u7684\u76ee\u5f55\uff0c\u627e\u5230python.exe\u6587\u4ef6\u3002\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff08cmd\uff09\uff0c\u5bfc\u822a\u5230\u5305\u542bpython.exe\u7684\u76ee\u5f55\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fd0\u884c\u60a8\u7684.py\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u4e0d\u9700\u8981\u5728\u7535\u8111\u4e0a\u5b89\u88c5Python\uff0c\u53ea\u9700\u8981\u4e00\u4e2a\u53ef\u4ee5\u8fd0\u884c\u7684\u4fbf\u643a\u7248\u672c\u5373\u53ef\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528\u5728\u7ebfPython\u7f16\u8bd1\u5668<\/h3>\n<\/p>\n<p><p>\u5982\u679c\u60a8\u65e0\u6cd5\u5728\u7535\u8111\u4e0a\u5b89\u88c5\u4efb\u4f55\u8f6f\u4ef6\uff0c\u4f7f\u7528\u5728\u7ebfPython\u7f16\u8bd1\u5668\u4e5f\u662f\u4e00\u79cd\u89e3\u51b3\u65b9\u6848\u3002\u8bb8\u591a\u7f51\u7ad9\u63d0\u4f9b\u5728\u7ebfPython\u7f16\u8bd1\u670d\u52a1\uff0c\u5982Repl.it\u3001Google Colab\u7b49\u3002\u8fd9\u4e9b\u5e73\u53f0\u4e0d\u4ec5\u5141\u8bb8\u60a8\u7f16\u5199\u548c\u8fd0\u884cPython\u4ee3\u7801\uff0c\u8fd8\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u5e93\u548c\u5de5\u5177\u3002<\/p>\n<\/p>\n<p><h4>1. \u9009\u62e9\u4e00\u4e2a\u5728\u7ebf\u7f16\u8bd1\u5668<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u9009\u62e9\u4e00\u4e2a\u60a8\u559c\u6b22\u7684\u5728\u7ebfPython\u7f16\u8bd1\u5668\u3002Repl.it\u548cGoogle Colab\u662f\u4e24\u4e2a\u975e\u5e38\u6d41\u884c\u7684\u9009\u62e9\u3002\u5b83\u4eec\u4e0d\u4ec5\u652f\u6301Python\uff0c\u8fd8\u652f\u6301\u5176\u4ed6\u591a\u79cd\u7f16\u7a0b\u8bed\u8a00\u3002<\/p>\n<\/p>\n<p><h4>2. \u521b\u5efa\u65b0\u7684\u9879\u76ee\u6216\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u5728\u9009\u62e9\u7684\u5728\u7ebf\u7f16\u8bd1\u5668\u4e0a\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Python\u9879\u76ee\u6216\u811a\u672c\u3002\u5c06\u60a8\u7684.py\u6587\u4ef6\u5185\u5bb9\u590d\u5236\u7c98\u8d34\u5230\u7f16\u8f91\u5668\u4e2d\u3002<\/p>\n<\/p>\n<p><h4>3. \u8fd0\u884c\u4ee3\u7801<\/h4>\n<\/p>\n<p><p>\u70b9\u51fb\u8fd0\u884c\u6309\u94ae\uff0c\u5373\u53ef\u5728\u6d4f\u89c8\u5668\u4e2d\u770b\u5230\u4ee3\u7801\u7684\u6267\u884c\u7ed3\u679c\u3002\u8fd9\u79cd\u65b9\u6cd5\u4e0d\u9700\u8981\u5728\u672c\u5730\u7535\u8111\u4e0a\u5b89\u88c5\u4efb\u4f55\u8f6f\u4ef6\uff0c\u53ea\u9700\u8981\u4e00\u4e2a\u7a33\u5b9a\u7684\u4e92\u8054\u7f51\u8fde\u63a5\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u4f7f\u7528\u7b2c\u4e09\u65b9\u5de5\u5177\u5c06.py\u6587\u4ef6\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u5c06.py\u6587\u4ef6\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\uff08EXE\uff09\u662f\u53e6\u4e00\u79cd\u89e3\u51b3\u65b9\u6848\u3002\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u8ba9\u60a8\u5728\u6ca1\u6709\u5b89\u88c5Python\u7684\u7535\u8111\u4e0a\u8fd0\u884cPython\u811a\u672c\u3002PyInstaller\u3001cx_Freeze\u7b49\u5de5\u5177\u53ef\u4ee5\u5e2e\u52a9\u60a8\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u3002<\/p>\n<\/p>\n<p><h4>1. \u5b89\u88c5PyInstaller<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u5728\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u7684\u7535\u8111\u4e0a\u5b89\u88c5PyInstaller\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pyinstaller<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u8f6c\u6362.py\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u5728\u5b89\u88c5\u4e86PyInstaller\u7684\u7535\u8111\u4e0a\uff0c\u6253\u5f00\u547d\u4ee4\u63d0\u793a\u7b26\uff0c\u5bfc\u822a\u5230\u60a8\u7684.py\u6587\u4ef6\u6240\u5728\u76ee\u5f55\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5c06.py\u6587\u4ef6\u8f6c\u6362\u4e3a\u53ef\u6267\u884c\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyinstaller --onefile your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u547d\u4ee4\u4f1a\u5728dist\u76ee\u5f55\u4e0b\u751f\u6210\u4e00\u4e2a\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u60a8\u53ef\u4ee5\u5c06\u5176\u590d\u5236\u5230\u6ca1\u6709\u5b89\u88c5Python\u7684\u7535\u8111\u4e0a\u8fd0\u884c\u3002<\/p>\n<\/p>\n<p><h4>3. \u8fd0\u884c\u53ef\u6267\u884c\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u5728\u6ca1\u6709\u5b89\u88c5Python\u7684\u7535\u8111\u4e0a\uff0c\u53cc\u51fb\u751f\u6210\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5373\u53ef\u8fd0\u884c\u60a8\u7684Python\u811a\u672c\u3002\u8fd9\u4e2a\u65b9\u6cd5\u9700\u8981\u5728\u4e00\u53f0\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u7684\u7535\u8111\u4e0a\u8fdb\u884c\u8f6c\u6362\uff0c\u4f46\u4e00\u65e6\u751f\u6210\u4e86\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u5c31\u4e0d\u518d\u9700\u8981Python\u73af\u5883\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u4f7f\u7528Docker\u5bb9\u5668<\/h3>\n<\/p>\n<p><p>Docker\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u5e73\u53f0\uff0c\u5141\u8bb8\u60a8\u5728\u4efb\u4f55\u73af\u5883\u4e2d\u6784\u5efa\u3001\u6d4b\u8bd5\u548c\u90e8\u7f72\u5e94\u7528\u7a0b\u5e8f\u3002\u901a\u8fc7Docker\uff0c\u60a8\u53ef\u4ee5\u5c06Python\u548c\u60a8\u7684.py\u6587\u4ef6\u6253\u5305\u6210\u4e00\u4e2a\u5bb9\u5668\uff0c\u5e76\u5728\u4efb\u4f55\u652f\u6301Docker\u7684\u7535\u8111\u4e0a\u8fd0\u884c\u3002<\/p>\n<\/p>\n<p><h4>1. \u5b89\u88c5Docker<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u786e\u4fdd\u5728\u76ee\u6807\u7535\u8111\u4e0a\u5b89\u88c5\u4e86Docker\u3002\u5982\u679c\u6ca1\u6709\uff0c\u60a8\u9700\u8981\u4eceDocker\u7684\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5e76\u5b89\u88c5Docker\u3002<\/p>\n<\/p>\n<p><h4>2. \u521b\u5efaDockerfile<\/h4>\n<\/p>\n<p><p>\u5728\u5df2\u7ecf\u5b89\u88c5\u4e86Docker\u7684\u7535\u8111\u4e0a\uff0c\u521b\u5efa\u4e00\u4e2aDockerfile\u6765\u5b9a\u4e49\u5bb9\u5668\u7684\u6784\u5efa\u8fc7\u7a0b\u3002Dockerfile\u7684\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-dockerfile\">FROM python:3.8-slim<\/p>\n<p>COPY your_script.py \/app\/your_script.py<\/p>\n<p>WORKDIR \/app<\/p>\n<p>CMD [&quot;python&quot;, &quot;your_script.py&quot;]<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3. \u6784\u5efaDocker\u955c\u50cf<\/h4>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\uff0c\u5bfc\u822a\u5230Dockerfile\u6240\u5728\u76ee\u5f55\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6784\u5efaDocker\u955c\u50cf\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">docker build -t your_script_image .<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>4. \u8fd0\u884cDocker\u5bb9\u5668<\/h4>\n<\/p>\n<p><p>\u5728\u76ee\u6807\u7535\u8111\u4e0a\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fd0\u884cDocker\u5bb9\u5668\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">docker run your_script_image<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u79cd\u65b9\u6cd5\u9700\u8981\u5728\u76ee\u6807\u7535\u8111\u4e0a\u5b89\u88c5Docker\uff0c\u4f46\u4e00\u65e6Docker\u5bb9\u5668\u6784\u5efa\u5b8c\u6210\uff0c\u8fd0\u884c\u8d77\u6765\u5c31\u975e\u5e38\u65b9\u4fbf\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u4f7f\u7528\u865a\u62df\u673a<\/h3>\n<\/p>\n<p><p>\u865a\u62df\u673a\uff08Virtual Machine\uff09\u662f\u4e00\u79cd\u8f6f\u4ef6\u6a21\u62df\u7684\u8ba1\u7b97\u673a\u7cfb\u7edf\uff0c\u53ef\u4ee5\u5728\u4e00\u53f0\u7269\u7406\u8ba1\u7b97\u673a\u4e0a\u8fd0\u884c\u591a\u4e2a\u865a\u62df\u8ba1\u7b97\u673a\u3002\u60a8\u53ef\u4ee5\u5728\u865a\u62df\u673a\u4e2d\u5b89\u88c5Python\u5e76\u8fd0\u884c\u60a8\u7684.py\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>1. \u5b89\u88c5\u865a\u62df\u673a\u8f6f\u4ef6<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u5728\u76ee\u6807\u7535\u8111\u4e0a\u5b89\u88c5\u865a\u62df\u673a\u8f6f\u4ef6\uff0c\u5982Oracle VM VirtualBox\u3001VMware\u7b49\u3002<\/p>\n<\/p>\n<p><h4>2. \u521b\u5efa\u865a\u62df\u673a<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528\u865a\u62df\u673a\u8f6f\u4ef6\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u673a\uff0c\u5e76\u5b89\u88c5\u4e00\u4e2a\u64cd\u4f5c\u7cfb\u7edf\uff0c\u5982Ubuntu\u3001Windows\u7b49\u3002<\/p>\n<\/p>\n<p><h4>3. \u5b89\u88c5Python<\/h4>\n<\/p>\n<p><p>\u5728\u865a\u62df\u673a\u7684\u64cd\u4f5c\u7cfb\u7edf\u4e2d\u5b89\u88c5Python\u3002\u53ef\u4ee5\u901a\u8fc7\u5305\u7ba1\u7406\u5668\u6216\u4ecePython\u5b98\u65b9\u7f51\u7ad9\u4e0b\u8f7d\u5b89\u88c5\u5305\u8fdb\u884c\u5b89\u88c5\u3002<\/p>\n<\/p>\n<p><h4>4. \u8fd0\u884c.py\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u5c06\u60a8\u7684.py\u6587\u4ef6\u590d\u5236\u5230\u865a\u62df\u673a\u4e2d\uff0c\u7136\u540e\u5728\u865a\u62df\u673a\u4e2d\u8fd0\u884cPython\u811a\u672c\u3002\u8fd9\u4e2a\u65b9\u6cd5\u867d\u7136\u590d\u6742\uff0c\u4f46\u4e3a\u60a8\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5b8c\u5168\u9694\u79bb\u7684\u73af\u5883\u6765\u8fd0\u884cPython\u811a\u672c\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u4f7f\u7528Jupyter Notebook<\/h3>\n<\/p>\n<p><p>Jupyter Notebook\u662f\u4e00\u79cd\u4ea4\u4e92\u5f0f\u7f16\u7a0b\u73af\u5883\uff0c\u5141\u8bb8\u60a8\u7f16\u5199\u548c\u8fd0\u884c\u4ee3\u7801\u3001\u53ef\u89c6\u5316\u6570\u636e\u7b49\u3002\u60a8\u53ef\u4ee5\u5c06Jupyter Notebook\u5b89\u88c5\u5728\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\uff0c\u901a\u8fc7\u6d4f\u89c8\u5668\u8bbf\u95ee\u5e76\u8fd0\u884cPython\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h4>1. \u5b89\u88c5Jupyter Notebook<\/h4>\n<\/p>\n<p><p>\u5728\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u7684\u7535\u8111\u4e0a\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Jupyter Notebook\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install notebook<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u542f\u52a8Jupyter Notebook<\/h4>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\uff0c\u5bfc\u822a\u5230\u60a8\u7684\u5de5\u4f5c\u76ee\u5f55\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8Jupyter Notebook\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">jupyter notebook<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3. \u8fdc\u7a0b\u8bbf\u95ee<\/h4>\n<\/p>\n<p><p>\u5c06Jupyter Notebook\u914d\u7f6e\u4e3a\u8fdc\u7a0b\u8bbf\u95ee\u6a21\u5f0f\uff0c\u5e76\u5728\u76ee\u6807\u7535\u8111\u7684\u6d4f\u89c8\u5668\u4e2d\u8bbf\u95ee\u3002\u60a8\u53ef\u4ee5\u5728\u6d4f\u89c8\u5668\u4e2d\u7f16\u5199\u548c\u8fd0\u884cPython\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u4f7f\u7528Python Anywhere<\/h3>\n<\/p>\n<p><p>Python Anywhere\u662f\u4e00\u4e2a\u57fa\u4e8e\u4e91\u7684Python\u5f00\u53d1\u73af\u5883\uff0c\u5141\u8bb8\u60a8\u5728\u4efb\u4f55\u5730\u65b9\u7f16\u5199\u548c\u8fd0\u884cPython\u4ee3\u7801\u3002\u60a8\u53ef\u4ee5\u5728Python Anywhere\u4e0a\u521b\u5efa\u8d26\u6237\uff0c\u4e0a\u4f20\u60a8\u7684.py\u6587\u4ef6\uff0c\u5e76\u8fd0\u884c\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h4>1. \u6ce8\u518c\u8d26\u6237<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u5728Python Anywhere\u5b98\u65b9\u7f51\u7ad9\u6ce8\u518c\u4e00\u4e2a\u8d26\u6237\u3002<\/p>\n<\/p>\n<p><h4>2. \u4e0a\u4f20.py\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u767b\u5f55\u540e\uff0c\u4e0a\u4f20\u60a8\u7684.py\u6587\u4ef6\u5230Python Anywhere\u7684\u6587\u4ef6\u7cfb\u7edf\u3002<\/p>\n<\/p>\n<p><h4>3. \u8fd0\u884c\u4ee3\u7801<\/h4>\n<\/p>\n<p><p>\u5728Python Anywhere\u7684\u7ec8\u7aef\u6216\u7f16\u8f91\u5668\u4e2d\u8fd0\u884c\u60a8\u7684.py\u6587\u4ef6\u3002\u8fd9\u4e2a\u65b9\u6cd5\u4e0d\u9700\u8981\u5728\u672c\u5730\u7535\u8111\u4e0a\u5b89\u88c5\u4efb\u4f55\u8f6f\u4ef6\uff0c\u53ea\u9700\u8981\u4e00\u4e2a\u6d4f\u89c8\u5668\u548c\u4e92\u8054\u7f51\u8fde\u63a5\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u4f7f\u7528AWS Lambda<\/h3>\n<\/p>\n<p><p>AWS Lambda\u662f\u4e9a\u9a6c\u900a\u63d0\u4f9b\u7684\u4e00\u79cd\u65e0\u670d\u52a1\u5668\u8ba1\u7b97\u670d\u52a1\uff0c\u5141\u8bb8\u60a8\u8fd0\u884c\u4ee3\u7801\u800c\u65e0\u9700\u9884\u7f6e\u6216\u7ba1\u7406\u670d\u52a1\u5668\u3002\u60a8\u53ef\u4ee5\u5c06Python\u4ee3\u7801\u90e8\u7f72\u5230AWS Lambda\uff0c\u5e76\u901a\u8fc7API\u8c03\u7528\u6765\u89e6\u53d1\u4ee3\u7801\u6267\u884c\u3002<\/p>\n<\/p>\n<p><h4>1. \u521b\u5efaLambda\u51fd\u6570<\/h4>\n<\/p>\n<p><p>\u767b\u5f55AWS\u7ba1\u7406\u63a7\u5236\u53f0\uff0c\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Lambda\u51fd\u6570\uff0c\u5e76\u9009\u62e9Python\u4f5c\u4e3a\u8fd0\u884c\u65f6\u73af\u5883\u3002<\/p>\n<\/p>\n<p><h4>2. \u4e0a\u4f20\u4ee3\u7801<\/h4>\n<\/p>\n<p><p>\u5c06\u60a8\u7684.py\u6587\u4ef6\u5185\u5bb9\u590d\u5236\u7c98\u8d34\u5230Lambda\u51fd\u6570\u7684\u7f16\u8f91\u5668\u4e2d\uff0c\u6216\u8005\u5c06\u4ee3\u7801\u6253\u5305\u6210ZIP\u6587\u4ef6\u5e76\u4e0a\u4f20\u3002<\/p>\n<\/p>\n<p><h4>3. \u914d\u7f6e\u89e6\u53d1\u5668<\/h4>\n<\/p>\n<p><p>\u914d\u7f6eAPI Gateway\u6216\u5176\u4ed6\u89e6\u53d1\u5668\u6765\u8c03\u7528\u60a8\u7684Lambda\u51fd\u6570\u3002\u8fd9\u4e2a\u65b9\u6cd5\u9002\u5408\u9700\u8981\u901a\u8fc7\u4e92\u8054\u7f51\u89e6\u53d1\u4ee3\u7801\u6267\u884c\u7684\u573a\u666f\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u51e0\u79cd\u65b9\u6cd5\uff0c\u60a8\u53ef\u4ee5\u5728\u6ca1\u6709\u5b89\u88c5Python\u7684\u7535\u8111\u4e0a\u8fd0\u884c.py\u6587\u4ef6\u3002\u6839\u636e\u5177\u4f53\u60c5\u51b5\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\uff0c\u53ef\u4ee5\u6709\u6548\u5730\u89e3\u51b3\u95ee\u9898\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728\u6ca1\u6709\u5b89\u88c5Python\u7684\u7535\u8111\u4e0a\u8fd0\u884c.py\u6587\u4ef6\uff1f<\/strong><br \/>\u5728\u6ca1\u6709\u5b89\u88c5Python\u7684\u7535\u8111\u4e0a\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528\u4e00\u4e9b\u5728\u7ebfPython\u7f16\u8bd1\u5668\u3002\u8bb8\u591a\u7f51\u7ad9\u5141\u8bb8\u7528\u6237\u76f4\u63a5\u5728\u6d4f\u89c8\u5668\u4e2d\u8f93\u5165\u6216\u4e0a\u4f20.py\u6587\u4ef6\uff0c\u4e4b\u540e\u5c31\u53ef\u4ee5\u8fd0\u884c\u4ee3\u7801\u3002\u8fd9\u79cd\u65b9\u5f0f\u4e0d\u9700\u8981\u4efb\u4f55\u672c\u5730\u5b89\u88c5\uff0c\u975e\u5e38\u65b9\u4fbf\u3002<\/p>\n<p><strong>\u662f\u5426\u6709\u4efb\u4f55\u5de5\u5177\u53ef\u4ee5\u8ba9\u6211\u5728\u6ca1\u6709Python\u7684\u60c5\u51b5\u4e0b\u8fd0\u884c.py\u6587\u4ef6\uff1f<\/strong><br \/>\u786e\u5b9e\u5b58\u5728\u4e00\u4e9b\u5de5\u5177\u548c\u5e94\u7528\u7a0b\u5e8f\uff0c\u5982PyInstaller\u548cPyOxidizer\uff0c\u5b83\u4eec\u80fd\u591f\u5c06Python\u811a\u672c\u6253\u5305\u6210\u72ec\u7acb\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u8fd9\u6837\uff0c\u60a8\u5c31\u53ef\u4ee5\u5728\u4e0d\u5b89\u88c5Python\u7684\u60c5\u51b5\u4e0b\u76f4\u63a5\u8fd0\u884c\u8fd9\u4e2a\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<p><strong>\u4f7f\u7528\u865a\u62df\u73af\u5883\u662f\u5426\u53ef\u4ee5\u5e2e\u52a9\u6211\u5728\u6ca1\u6709Python\u7684\u7535\u8111\u4e0a\u8fd0\u884c.py\u6587\u4ef6\uff1f<\/strong><br \/>\u865a\u62df\u73af\u5883\u4e3b\u8981\u7528\u4e8e\u7ba1\u7406\u9879\u76ee\u4f9d\u8d56\u548c\u5305\u7248\u672c\u3002\u867d\u7136\u5b83\u5bf9\u5df2\u5b89\u88c5Python\u7684\u7cfb\u7edf\u975e\u5e38\u6709\u7528\uff0c\u4f46\u5728\u6ca1\u6709Python\u73af\u5883\u7684\u7535\u8111\u4e0a\u65e0\u6cd5\u76f4\u63a5\u8fd0\u884c.py\u6587\u4ef6\u3002\u5982\u679c\u5e0c\u671b\u9694\u79bb\u9879\u76ee\u73af\u5883\uff0c\u4ecd\u9700\u5728\u6709Python\u7684\u7535\u8111\u4e0a\u521b\u5efa\u865a\u62df\u73af\u5883\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728\u6ca1\u6709\u5b89\u88c5Python\u7684\u7535\u8111\u4e0a\u8fd0\u884c.py\u6587\u4ef6\u786e\u5b9e\u662f\u4e00\u4e2a\u6311\u6218\uff0c\u4f46\u662f\u6709\u4e00\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u5e2e\u52a9\u60a8\u5b9e\u73b0\u8fd9\u4e00\u76ee\u6807\u3002\u4f7f\u7528\u4fbf\u643a\u7248\u672c [&hellip;]","protected":false},"author":3,"featured_media":1066907,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1066904"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1066904"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1066904\/revisions"}],"predecessor-version":[{"id":1066909,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1066904\/revisions\/1066909"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1066907"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1066904"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1066904"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1066904"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}