{"id":1007236,"date":"2024-12-27T10:51:36","date_gmt":"2024-12-27T02:51:36","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1007236.html"},"modified":"2024-12-27T10:51:40","modified_gmt":"2024-12-27T02:51:40","slug":"python%e5%a6%82%e4%bd%95%e8%ae%be%e7%bd%ae%e8%87%aa%e5%90%af%e5%8a%a8","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1007236.html","title":{"rendered":"Python\u5982\u4f55\u8bbe\u7f6e\u81ea\u542f\u52a8"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25083030\/32bc8270-8e6f-486d-92c4-3442436ce991.webp\" alt=\"Python\u5982\u4f55\u8bbe\u7f6e\u81ea\u542f\u52a8\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\u8bbe\u7f6e\u81ea\u542f\u52a8\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u64cd\u4f5c\u7cfb\u7edf\u7684\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\u3001\u521b\u5efa\u542f\u52a8\u811a\u672c\u3001\u4fee\u6539\u6ce8\u518c\u8868\u3001\u5229\u7528\u7cfb\u7edf\u670d\u52a1\u3002<\/strong>\u5176\u4e2d\uff0c\u4f7f\u7528\u64cd\u4f5c\u7cfb\u7edf\u7684\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\u662f\u6700\u5e38\u89c1\u4e14\u7b80\u5355\u7684\u65b9\u6cd5\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u901a\u8fc7\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\u8fdb\u884c\u8bbe\u7f6e\u7684\u65b9\u6cd5\u3002<\/p>\n<\/p>\n<p><p>\u8981\u4f7f\u7528\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\u8bbe\u7f6ePython\u811a\u672c\u81ea\u542f\u52a8\uff0c\u53ef\u4ee5\u6309\u7167\u4ee5\u4e0b\u6b65\u9aa4\u64cd\u4f5c\uff1a<\/p>\n<\/p>\n<ol>\n<li>\u6253\u5f00\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\uff1a\u5728Windows\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u641c\u7d22\u680f\u8f93\u5165\u201c\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\u201d\u5e76\u6253\u5f00\u3002\u5728macOS\u548cLinux\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528cron\u4f5c\u4e1a\u6216\u5176\u4ed6\u8ba1\u5212\u4efb\u52a1\u7ba1\u7406\u5de5\u5177\u3002<\/li>\n<li>\u521b\u5efa\u4efb\u52a1\uff1a\u5728\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\u4e2d\uff0c\u9009\u62e9\u201c\u521b\u5efa\u4efb\u52a1\u201d\u9009\u9879\u3002<\/li>\n<li>\u914d\u7f6e\u4efb\u52a1\uff1a\u5728\u4efb\u52a1\u7684\u5e38\u89c4\u8bbe\u7f6e\u4e2d\uff0c\u7ed9\u4efb\u52a1\u547d\u540d\uff0c\u5e76\u9009\u62e9\u5728\u767b\u5f55\u65f6\u8fd0\u884c\u3002<\/li>\n<li>\u52a8\u4f5c\u8bbe\u7f6e\uff1a\u5728\u52a8\u4f5c\u9009\u9879\u5361\u4e2d\uff0c\u9009\u62e9\u201c\u542f\u52a8\u7a0b\u5e8f\u201d\uff0c\u7136\u540e\u9009\u62e9\u4f60\u7684Python\u89e3\u91ca\u5668\uff08\u901a\u5e38\u662fpython.exe\uff09\u7684\u8def\u5f84\uff0c\u5e76\u5728\u201c\u6dfb\u52a0\u53c2\u6570\u201d\u6846\u4e2d\u8f93\u5165\u4f60\u7684Python\u811a\u672c\u8def\u5f84\u3002<\/li>\n<li>\u6761\u4ef6\u548c\u8bbe\u7f6e\uff1a\u5728\u6761\u4ef6\u9009\u9879\u5361\u4e2d\uff0c\u53d6\u6d88\u9009\u62e9\u201c\u4ec5\u5728\u8ba1\u7b97\u673a\u4f7f\u7528\u4ea4\u6d41\u7535\u6e90\u65f6\u624d\u542f\u52a8\u201d\u9009\u9879\u3002\u5728\u8bbe\u7f6e\u9009\u9879\u5361\u4e2d\uff0c\u6839\u636e\u9700\u8981\u8c03\u6574\u8bbe\u7f6e\u3002<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u4f7fPython\u811a\u672c\u5728\u7cfb\u7edf\u542f\u52a8\u65f6\u81ea\u52a8\u8fd0\u884c\u3002\u63a5\u4e0b\u6765\u5c06\u66f4\u8be6\u7ec6\u5730\u4ecb\u7ecd\u5176\u4ed6\u65b9\u6cd5\u53ca\u76f8\u5173\u6ce8\u610f\u4e8b\u9879\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\u8bbe\u7f6e\u81ea\u542f\u52a8<\/p>\n<\/p>\n<p><p>\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\u662fWindows\u7cfb\u7edf\u5185\u7f6e\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u5e2e\u52a9\u7528\u6237\u5728\u6307\u5b9a\u65f6\u95f4\u6216\u4e8b\u4ef6\u4e0b\u8fd0\u884c\u7a0b\u5e8f\u3002\u5728Python\u8bbe\u7f6e\u81ea\u542f\u52a8\u65f6\uff0c\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\u662f\u975e\u5e38\u5b9e\u7528\u7684\u3002<\/p>\n<\/p>\n<p><h3>1.1 \u521b\u5efa\u4efb\u52a1<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u5728Windows\u4e2d\u641c\u7d22\u5e76\u6253\u5f00\u201c\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\u201d\u3002\u5728\u5de6\u4fa7\u9762\u677f\u4e2d\uff0c\u70b9\u51fb\u201c\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\u5e93\u201d\uff0c\u7136\u540e\u5728\u53f3\u4fa7\u9762\u677f\u4e2d\u9009\u62e9\u201c\u521b\u5efa\u4efb\u52a1\u201d\u3002<\/p>\n<\/p>\n<p><h3>1.2 \u914d\u7f6e\u4efb\u52a1<\/h3>\n<\/p>\n<p><p>\u5728\u201c\u521b\u5efa\u4efb\u52a1\u201d\u7a97\u53e3\u4e2d\uff0c\u9996\u5148\u5728\u201c\u5e38\u89c4\u201d\u9009\u9879\u5361\u4e2d\u4e3a\u4f60\u7684\u4efb\u52a1\u547d\u540d\uff0c\u5e76\u9009\u62e9\u201c\u4e3a\u7528\u6237\u767b\u5f55\u65f6\u8fd0\u884c\u201d\u3002\u8fd9\u5c06\u786e\u4fdd\u811a\u672c\u5728\u7528\u6237\u767b\u5f55\u65f6\u81ea\u52a8\u542f\u52a8\u3002<\/p>\n<\/p>\n<p><h3>1.3 \u8bbe\u7f6e\u89e6\u53d1\u5668<\/h3>\n<\/p>\n<p><p>\u5728\u201c\u89e6\u53d1\u5668\u201d\u9009\u9879\u5361\u4e2d\uff0c\u70b9\u51fb\u201c\u65b0\u5efa\u201d\u6309\u94ae\u3002\u5728\u5f39\u51fa\u7684\u7a97\u53e3\u4e2d\uff0c\u9009\u62e9\u201c\u5728\u767b\u5f55\u65f6\u201d\u4f5c\u4e3a\u89e6\u53d1\u6761\u4ef6\u3002\u8fd9\u610f\u5473\u7740\u6bcf\u5f53\u7528\u6237\u767b\u5f55\u7cfb\u7edf\u65f6\uff0c\u4efb\u52a1\u5c06\u81ea\u52a8\u542f\u52a8\u3002<\/p>\n<\/p>\n<p><h3>1.4 \u8bbe\u7f6e\u52a8\u4f5c<\/h3>\n<\/p>\n<p><p>\u5728\u201c\u52a8\u4f5c\u201d\u9009\u9879\u5361\u4e2d\uff0c\u70b9\u51fb\u201c\u65b0\u5efa\u201d\u6309\u94ae\u3002\u5728\u201c\u64cd\u4f5c\u201d\u4e0b\u62c9\u83dc\u5355\u4e2d\u9009\u62e9\u201c\u542f\u52a8\u7a0b\u5e8f\u201d\u3002\u5728\u201c\u7a0b\u5e8f\/\u811a\u672c\u201d\u6846\u4e2d\uff0c\u6d4f\u89c8\u5e76\u9009\u62e9Python\u89e3\u91ca\u5668\u7684\u8def\u5f84\uff08\u4f8b\u5982\uff0cC:\\Python39\\python.exe\uff09\u3002\u7136\u540e\uff0c\u5728\u201c\u6dfb\u52a0\u53c2\u6570\u201d\u6846\u4e2d\u8f93\u5165\u4f60\u7684Python\u811a\u672c\u7684\u8def\u5f84\uff08\u4f8b\u5982\uff0cC:\\Scripts\\myscript.py\uff09\u3002<\/p>\n<\/p>\n<p><h3>1.5 \u6761\u4ef6\u548c\u8bbe\u7f6e<\/h3>\n<\/p>\n<p><p>\u5728\u201c\u6761\u4ef6\u201d\u9009\u9879\u5361\u4e2d\uff0c\u53d6\u6d88\u9009\u62e9\u201c\u4ec5\u5728\u8ba1\u7b97\u673a\u4f7f\u7528\u4ea4\u6d41\u7535\u6e90\u65f6\u624d\u542f\u52a8\u201d\u9009\u9879\uff0c\u4ee5\u786e\u4fdd\u4efb\u52a1\u5728\u7535\u6c60\u4f9b\u7535\u65f6\u4e5f\u80fd\u8fd0\u884c\u3002\u5728\u201c\u8bbe\u7f6e\u201d\u9009\u9879\u5361\u4e2d\uff0c\u6839\u636e\u9700\u8981\u8c03\u6574\u4efb\u52a1\u7684\u5176\u4ed6\u8bbe\u7f6e\uff0c\u4f8b\u5982\u5141\u8bb8\u4efb\u52a1\u8fd0\u884c\u8d85\u8fc7\u6307\u5b9a\u65f6\u95f4\u6216\u5728\u4efb\u52a1\u5931\u8d25\u540e\u91cd\u8bd5\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u8fd9\u4e9b\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\u8bbe\u7f6ePython\u811a\u672c\u5728\u7cfb\u7edf\u542f\u52a8\u65f6\u81ea\u52a8\u8fd0\u884c\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u521b\u5efa\u542f\u52a8\u811a\u672c<\/p>\n<\/p>\n<p><p>\u9664\u4e86\u4f7f\u7528\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\u5916\uff0c\u521b\u5efa\u542f\u52a8\u811a\u672c\u4e5f\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u65b9\u6cd5\u3002\u901a\u8fc7\u5728\u7cfb\u7edf\u542f\u52a8\u6587\u4ef6\u5939\u4e2d\u6dfb\u52a0Python\u811a\u672c\u7684\u5feb\u6377\u65b9\u5f0f\uff0c\u811a\u672c\u53ef\u4ee5\u5728\u7528\u6237\u767b\u5f55\u65f6\u81ea\u52a8\u8fd0\u884c\u3002<\/p>\n<\/p>\n<p><h3>2.1 \u521b\u5efa\u811a\u672c\u5feb\u6377\u65b9\u5f0f<\/h3>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u5728\u6587\u4ef6<a href=\"https:\/\/docs.pingcode.com\/blog\/project-management\/58557.html\" target=\"_blank\">\u8d44\u6e90\u7ba1\u7406<\/a>\u5668\u4e2d\u627e\u5230\u4f60\u7684Python\u811a\u672c\u3002\u53f3\u952e\u70b9\u51fb\u811a\u672c\u6587\u4ef6\uff0c\u5e76\u9009\u62e9\u201c\u521b\u5efa\u5feb\u6377\u65b9\u5f0f\u201d\u3002<\/p>\n<\/p>\n<p><h3>2.2 \u5c06\u5feb\u6377\u65b9\u5f0f\u79fb\u52a8\u5230\u542f\u52a8\u6587\u4ef6\u5939<\/h3>\n<\/p>\n<p><p>\u5728Windows\u4e2d\uff0c\u542f\u52a8\u6587\u4ef6\u5939\u7684\u4f4d\u7f6e\u901a\u5e38\u662fC:\\Users[\u7528\u6237\u540d]\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Startup\u3002\u5c06\u4e4b\u524d\u521b\u5efa\u7684\u811a\u672c\u5feb\u6377\u65b9\u5f0f\u79fb\u52a8\u5230\u6b64\u6587\u4ef6\u5939\u4e2d\u3002<\/p>\n<\/p>\n<p><h3>2.3 \u6d4b\u8bd5\u542f\u52a8\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u91cd\u542f\u8ba1\u7b97\u673a\u6216\u91cd\u65b0\u767b\u5f55\u7cfb\u7edf\uff0c\u68c0\u67e5Python\u811a\u672c\u662f\u5426\u5728\u542f\u52a8\u65f6\u81ea\u52a8\u8fd0\u884c\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u4fee\u6539\u6ce8\u518c\u8868<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4fee\u6539\u6ce8\u518c\u8868\uff0c\u53ef\u4ee5\u5728\u7cfb\u7edf\u542f\u52a8\u65f6\u8fd0\u884cPython\u811a\u672c\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u5408\u4e8e\u9700\u8981\u5728\u7528\u6237\u767b\u5f55\u524d\u8fd0\u884c\u7684\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><h3>3.1 \u6253\u5f00\u6ce8\u518c\u8868\u7f16\u8f91\u5668<\/h3>\n<\/p>\n<p><p>\u6309\u4e0bWindows\u952e+R\uff0c\u8f93\u5165\u201cregedit\u201d\u5e76\u6309Enter\u952e\uff0c\u6253\u5f00\u6ce8\u518c\u8868\u7f16\u8f91\u5668\u3002<\/p>\n<\/p>\n<p><h3>3.2 \u5bfc\u822a\u5230\u542f\u52a8\u9879<\/h3>\n<\/p>\n<p><p>\u5728\u6ce8\u518c\u8868\u7f16\u8f91\u5668\u4e2d\uff0c\u5bfc\u822a\u5230HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run\u3002\u8fd9\u662f\u5f53\u524d\u7528\u6237\u7684\u542f\u52a8\u9879\u4f4d\u7f6e\u3002<\/p>\n<\/p>\n<p><h3>3.3 \u6dfb\u52a0\u65b0\u9879<\/h3>\n<\/p>\n<p><p>\u5728\u53f3\u4fa7\u7a97\u53e3\u4e2d\uff0c\u53f3\u952e\u70b9\u51fb\u5e76\u9009\u62e9\u201c\u65b0\u5efa\u201d-&gt;\u201c\u5b57\u7b26\u4e32\u503c\u201d\u3002\u4e3a\u65b0\u9879\u547d\u540d\uff0c\u4f8b\u5982\u201cMyPythonScript\u201d\u3002\u53cc\u51fb\u65b0\u9879\uff0c\u5e76\u5728\u201c\u6570\u503c\u6570\u636e\u201d\u6846\u4e2d\u8f93\u5165Python\u811a\u672c\u7684\u5b8c\u6574\u8def\u5f84\uff08\u5305\u62ecPython\u89e3\u91ca\u5668\u7684\u8def\u5f84\uff09\u3002<\/p>\n<\/p>\n<p><h3>3.4 \u6d4b\u8bd5\u6ce8\u518c\u8868\u9879<\/h3>\n<\/p>\n<p><p>\u91cd\u542f\u8ba1\u7b97\u673a\u6216\u91cd\u65b0\u767b\u5f55\u7cfb\u7edf\uff0c\u786e\u8ba4Python\u811a\u672c\u662f\u5426\u5728\u542f\u52a8\u65f6\u81ea\u52a8\u8fd0\u884c\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u5229\u7528\u7cfb\u7edf\u670d\u52a1<\/p>\n<\/p>\n<p><p>\u5bf9\u4e8e\u9700\u8981\u5728\u7cfb\u7edf\u542f\u52a8\u524d\u8fd0\u884c\u7684\u811a\u672c\uff0c\u53ef\u4ee5\u5c06Python\u811a\u672c\u914d\u7f6e\u4e3aWindows\u670d\u52a1\u3002\u8fd9\u79cd\u65b9\u6cd5\u9002\u5408\u4e8e\u9700\u8981\u5728\u540e\u53f0\u8fd0\u884c\u7684\u957f\u671f\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><h3>4.1 \u5b89\u88c5Python\u670d\u52a1\u6a21\u5757<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u5c06Python\u811a\u672c\u914d\u7f6e\u4e3aWindows\u670d\u52a1\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5Python\u670d\u52a1\u6a21\u5757\u3002\u53ef\u4ee5\u4f7f\u7528pip\u5b89\u88c5pywin32\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install pywin32<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>4.2 \u521b\u5efa\u670d\u52a1\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u7f16\u5199\u4e00\u4e2aPython\u811a\u672c\uff0c\u5c06\u539f\u6709\u7684Python\u811a\u672c\u5305\u88c5\u4e3aWindows\u670d\u52a1\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import win32serviceutil<\/p>\n<p>import win32service<\/p>\n<p>import win32event<\/p>\n<p>class MyPythonService(win32serviceutil.ServiceFramework):<\/p>\n<p>    _svc_name_ = &quot;MyPythonService&quot;<\/p>\n<p>    _svc_display_name_ = &quot;My Python Service&quot;<\/p>\n<p>    _svc_description_ = &quot;This is my Python service.&quot;<\/p>\n<p>    def __init__(self, args):<\/p>\n<p>        win32serviceutil.ServiceFramework.__init__(self, args)<\/p>\n<p>        self.hW<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>tStop = win32event.CreateEvent(None, 0, 0, None)<\/p>\n<p>    def SvcDoRun(self):<\/p>\n<p>        import servicemanager<\/p>\n<p>        servicemanager.LogMsg(servicemanager.EVENTLOG_INFORMATION_TYPE, servicemanager.PYS_SERVICE_STARTED, (self._svc_name_, &#39;&#39;))<\/p>\n<p>        self.main()<\/p>\n<p>    def SvcStop(self):<\/p>\n<p>        self.ReportServiceStatus(win32service.SERVICE_STOP_PENDING)<\/p>\n<p>        win32event.SetEvent(self.hWaitStop)<\/p>\n<p>    def main(self):<\/p>\n<p>        # \u8fd9\u91cc\u662f\u4f60\u7684Python\u811a\u672c\u903b\u8f91<\/p>\n<p>        pass<\/p>\n<p>if __name__ == &#39;__main__&#39;:<\/p>\n<p>    win32serviceutil.HandleCommandLine(MyPythonService)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>4.3 \u5b89\u88c5\u670d\u52a1<\/h3>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u63d0\u793a\u7b26\u4e2d\uff0c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u4ee5\u5b89\u88c5\u670d\u52a1\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python my_service.py install<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u542f\u52a8\u670d\u52a1\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python my_service.py start<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>4.4 \u6d4b\u8bd5\u670d\u52a1<\/h3>\n<\/p>\n<p><p>\u91cd\u542f\u8ba1\u7b97\u673a\uff0c\u786e\u8ba4Python\u670d\u52a1\u662f\u5426\u5728\u542f\u52a8\u65f6\u81ea\u52a8\u8fd0\u884c\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u65b9\u6cd5\uff0c\u4f60\u53ef\u4ee5\u6839\u636e\u9700\u8981\u9009\u62e9\u5408\u9002\u7684\u65b9\u6cd5\u6765\u8bbe\u7f6ePython\u811a\u672c\u81ea\u542f\u52a8\u3002\u6bcf\u79cd\u65b9\u6cd5\u90fd\u6709\u5176\u4f18\u7f3a\u70b9\uff0c\u5e94\u6839\u636e\u5177\u4f53\u5e94\u7528\u573a\u666f\u548c\u9700\u6c42\u8fdb\u884c\u9009\u62e9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Windows\u7cfb\u7edf\u4e0a\u8bbe\u7f6ePython\u811a\u672c\u81ea\u542f\u52a8\uff1f<\/strong><br \/>\u5728Windows\u7cfb\u7edf\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u5c06Python\u811a\u672c\u6dfb\u52a0\u5230\u542f\u52a8\u6587\u4ef6\u5939\u6765\u5b9e\u73b0\u81ea\u542f\u52a8\u3002\u9996\u5148\uff0c\u627e\u5230\u4f60\u7684Python\u811a\u672c\u6587\u4ef6\uff0c\u590d\u5236\u5b83\u3002\u63a5\u7740\uff0c\u6309\u4e0b\u201cWin + R\u201d\u7ec4\u5408\u952e\uff0c\u8f93\u5165\u201cshell:startup\u201d\u5e76\u56de\u8f66\uff0c\u8fd9\u5c06\u6253\u5f00\u542f\u52a8\u6587\u4ef6\u5939\u3002\u5c06\u4e4b\u524d\u590d\u5236\u7684\u811a\u672c\u7c98\u8d34\u5230\u8be5\u6587\u4ef6\u5939\u4e2d\u3002\u6bcf\u6b21\u5f00\u673a\u65f6\uff0c\u7cfb\u7edf\u4f1a\u81ea\u52a8\u8fd0\u884c\u6b64\u6587\u4ef6\u3002<\/p>\n<p><strong>\u5728Linux\u7cfb\u7edf\u4e2d\u5982\u4f55\u5b9e\u73b0Python\u811a\u672c\u81ea\u542f\u52a8\uff1f<\/strong><br \/>\u5728Linux\u7cfb\u7edf\u4e2d\uff0c\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7\u521b\u5efa\u4e00\u4e2a\u670d\u52a1\u6765\u5b9e\u73b0Python\u811a\u672c\u81ea\u542f\u52a8\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528systemd\u6765\u521b\u5efa\u4e00\u4e2a\u670d\u52a1\u5355\u5143\u6587\u4ef6\u3002\u9996\u5148\uff0c\u5c06\u4f60\u7684Python\u811a\u672c\u653e\u5728\u5408\u9002\u7684\u76ee\u5f55\u4e2d\uff0c\u7136\u540e\u521b\u5efa\u4e00\u4e2a<code>.service<\/code>\u6587\u4ef6\uff0c\u914d\u7f6e\u5176ExecStart\u4e3a\u4f60\u7684Python\u811a\u672c\u8def\u5f84\uff0c\u5e76\u5c06\u5176\u653e\u7f6e\u5728<code>\/etc\/systemd\/system\/<\/code>\u76ee\u5f55\u3002\u6700\u540e\uff0c\u542f\u7528\u670d\u52a1\u5e76\u542f\u52a8\u5b83\uff0c\u4f7f\u5176\u5728\u7cfb\u7edf\u542f\u52a8\u65f6\u81ea\u52a8\u8fd0\u884c\u3002<\/p>\n<p><strong>\u5982\u4f55\u4f7f\u7528\u4efb\u52a1\u8c03\u5ea6\u5668\u8bbe\u7f6ePython\u811a\u672c\u81ea\u542f\u52a8\uff1f<\/strong><br \/>\u5728Windows\u4e2d\uff0c\u4efb\u52a1\u8c03\u5ea6\u5668\u63d0\u4f9b\u4e86\u4e00\u4e2a\u7075\u6d3b\u7684\u65b9\u5f0f\u6765\u8bbe\u7f6ePython\u811a\u672c\u81ea\u542f\u52a8\u3002\u6253\u5f00\u4efb\u52a1\u8c03\u5ea6\u5668\uff0c\u521b\u5efa\u4e00\u4e2a\u57fa\u672c\u4efb\u52a1\uff0c\u8bbe\u5b9a\u89e6\u53d1\u5668\u4e3a\u201c\u5f00\u673a\u65f6\u201d\u3002\u5728\u64cd\u4f5c\u4e2d\uff0c\u9009\u62e9\u201c\u542f\u52a8\u7a0b\u5e8f\u201d\uff0c\u5e76\u8f93\u5165Python\u7684\u8def\u5f84\u548c\u4f60\u7684\u811a\u672c\u8def\u5f84\u3002\u8fd9\u6837\uff0c\u6bcf\u6b21\u5f00\u673a\u65f6\uff0c\u4efb\u52a1\u8c03\u5ea6\u5668\u90fd\u4f1a\u81ea\u52a8\u8fd0\u884c\u4f60\u7684Python\u811a\u672c\u3002<\/p>\n<p><strong>\u53ef\u4ee5\u901a\u8fc7\u54ea\u4e9b\u65b9\u6cd5\u5b9e\u73b0Python\u811a\u672c\u7684\u5b9a\u65f6\u81ea\u542f\u52a8\uff1f<\/strong><br \/>\u5b9e\u73b0Python\u811a\u672c\u7684\u5b9a\u65f6\u81ea\u542f\u52a8\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\uff0c\u4f8b\u5982\u4f7f\u7528\u64cd\u4f5c\u7cfb\u7edf\u7684\u4efb\u52a1\u8c03\u5ea6\u529f\u80fd\uff08\u5982Windows\u4efb\u52a1\u8c03\u5ea6\u5668\u6216Linux\u7684cron\u4f5c\u4e1a\uff09\uff0c\u6216\u8005\u4f7f\u7528\u7b2c\u4e09\u65b9\u5de5\u5177\uff08\u5982NSSM\u5728Windows\u4e0a\uff09\u3002\u65e0\u8bba\u9009\u62e9\u54ea\u79cd\u65b9\u5f0f\uff0c\u786e\u4fdd\u811a\u672c\u8def\u5f84\u548cPython\u89e3\u91ca\u5668\u8def\u5f84\u8bbe\u7f6e\u6b63\u786e\uff0c\u4ee5\u786e\u4fdd\u811a\u672c\u80fd\u591f\u987a\u5229\u6267\u884c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\u8bbe\u7f6e\u81ea\u542f\u52a8\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u4f7f\u7528\u64cd\u4f5c\u7cfb\u7edf\u7684\u4efb\u52a1\u8ba1\u5212\u7a0b\u5e8f\u3001\u521b\u5efa\u542f\u52a8\u811a\u672c\u3001\u4fee\u6539\u6ce8\u518c\u8868\u3001\u5229\u7528\u7cfb\u7edf\u670d\u52a1\u3002\u5176\u4e2d [&hellip;]","protected":false},"author":3,"featured_media":1007245,"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\/1007236"}],"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=1007236"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1007236\/revisions"}],"predecessor-version":[{"id":1007249,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1007236\/revisions\/1007249"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1007245"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1007236"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1007236"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1007236"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}