{"id":14286,"date":"2025-04-18T21:02:52","date_gmt":"2025-04-18T13:02:52","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/14286.html"},"modified":"2025-04-18T21:02:52","modified_gmt":"2025-04-18T13:02:52","slug":"python%e8%87%aa%e5%8a%a8%e5%8c%96%e8%bf%90%e7%bb%b4%ef%bc%9a%e4%b8%80%e9%94%ae%e6%8e%8c%e6%8e%a7%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%9a%84%e9%ab%98%e6%95%88%e4%b9%8b%e9%81%93","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/14286.html","title":{"rendered":"Python\u81ea\u52a8\u5316\u8fd0\u7ef4\uff1a\u4e00\u952e\u638c\u63a7\u670d\u52a1\u5668\u7684\u9ad8\u6548\u4e4b\u9053"},"content":{"rendered":"<p>\u300aPython OpenCV\u4ece\u83dc\u9e1f\u5230\u9ad8\u624b\u300b\u5e26\u4f60\u8fdb\u5165\u56fe\u50cf\u5904\u7406\u4e0e\u8ba1\u7b97\u673a\u89c6\u89c9\u7684\u5927\u95e8\uff01<\/p>\n<p>\u89e3\u9501Python\u7f16\u7a0b\u7684\u65e0\u9650\u53ef\u80fd\uff1a\u300a\u5947\u5999\u7684Python\u300b\u5e26\u4f60\u6f2b\u6e38\u4ee3\u7801\u4e16\u754c<\/p>\n<p>\u5728\u4e92\u8054\u7f51\u548c\u4e91\u8ba1\u7b97\u9ad8\u901f\u53d1\u5c55\u7684\u4eca\u5929\uff0c\u670d\u52a1\u5668\u6570\u91cf\u7684\u6307\u6570\u589e\u957f\u4f7f\u5f97\u624b\u52a8\u8fd0\u7ef4\u548c\u7ba1\u7406\u53d8\u5f97\u5f02\u5e38\u7e41\u7410\u3002Python\u51ed\u501f\u5176\u5f3a\u5927\u7684\u53ef\u8bfb\u6027\u548c\u4e30\u5bcc\u7684\u751f\u6001\u7cfb\u7edf\uff0c\u6210\u4e3a\u5b9e\u73b0\u81ea\u52a8\u5316\u8fd0\u7ef4\u7684\u7406\u60f3\u8bed\u8a00\u3002\u672c\u6587\u4ee5\u201cPython\u81ea\u52a8\u5316\u8fd0\u7ef4\uff1a\u7f16\u5199\u81ea\u52a8\u5316\u811a\u672c\u8fdb\u884c\u670d\u52a1\u5668\u7ba1\u7406\u201d\u4e3a\u4e3b\u9898\uff0c\u6df1\u5165\u63a2\u8ba8\u4e86\u5982\u4f55\u5229\u7528Python\u5728\u6279\u91cf\u5904\u7406\u3001\u5b9a\u65f6\u4efb\u52a1\u548c\u65e5\u5fd7\u6e05\u7406\u7b49\u65b9\u9762\u89e3\u653e\u8fd0\u7ef4\u4eba\u5458\u7684\u53cc\u624b\u3002\u6587\u7ae0\u4eceSSH\u8fde\u63a5\u3001\u6279\u91cf\u90e8\u7f72\u811a\u672c\u5230\u65e5\u5fd7\u5f52\u6863\u3001\u81ea\u52a8\u5316\u62a5\u8b66\u7b49\u591a\u4e2a\u89d2\u5ea6\u8fdb\u884c\u4e86\u8be6\u7ec6\u9610\u8ff0\u4e0e\u4ee3\u7801\u793a\u4f8b\uff0c\u5e76\u5206\u4eab\u4e86\u5e38\u89c1\u7684\u6700\u4f73\u5b9e\u8df5\u548c\u6027\u80fd\u4f18\u5316\u601d\u8def\u3002\u901a\u8fc7\u9605\u8bfb\u672c\u6587\uff0c\u8bfb\u8005\u53ef\u4ee5\u5feb\u901f\u638c\u63e1Python\u81ea\u52a8\u5316\u8fd0\u7ef4\u7684\u6838\u5fc3\u6280\u80fd\uff0c\u8fdb\u4e00\u6b65\u63d0\u5347\u8fd0\u7ef4\u6548\u7387\u4e0e\u7cfb\u7edf\u7a33\u5b9a\u6027\u3002<\/p>\n<hr>\n<h3>\u5f15\u8a00<\/h3>\n<p>\u5728\u670d\u52a1\u5668\u6570\u91cf\u8f83\u5c11\u7684\u65f6\u5019\uff0c\u8fd0\u7ef4\u4eba\u5458\u5f80\u5f80\u53ef\u4ee5\u624b\u52a8\u767b\u5f55\u6bcf\u53f0\u670d\u52a1\u5668\uff0c\u6267\u884c\u66f4\u65b0\u3001\u91cd\u542f\u3001\u65e5\u5fd7\u67e5\u770b\u7b49\u64cd\u4f5c\u3002\u7136\u800c\uff0c\u968f\u7740\u4e1a\u52a1\u7684\u5feb\u901f\u6269\u5f20\u4ee5\u53ca\u4e91\u8ba1\u7b97\u3001\u5bb9\u5668\u5316\u6280\u672f\u7684\u666e\u53ca\uff0c\u670d\u52a1\u5668\u89c4\u6a21\u8fc5\u901f\u589e\u5927\uff0c\u624b\u52a8\u64cd\u4f5c\u5e26\u6765\u7684\u6548\u7387\u95ee\u9898\u3001\u51fa\u9519\u98ce\u9669\u3001\u53ef\u91cd\u590d\u6027\u4f4e\u7b49\u7f3a\u70b9\u53d8\u5f97\u975e\u5e38\u7a81\u51fa\u3002\u4e3a\u4e86\u6ee1\u8db3\u5927\u89c4\u6a21\u96c6\u7fa4\u7ba1\u7406\u7684\u9700\u6c42\uff0c\u81ea\u52a8\u5316\u8fd0\u7ef4\u6210\u4e3a\u8d8a\u6765\u8d8a\u591a\u4f01\u4e1a\u7684\u5fc5\u7136\u9009\u62e9\u3002<\/p>\n<p>Python\u5728\u81ea\u52a8\u5316\u8fd0\u7ef4\u9886\u57df\u4f18\u52bf\u660e\u663e\uff1a<\/p>\n<li>\u8bed\u6cd5\u7b80\u6d01\uff1a\u4f4e\u95e8\u69db\u3001\u6613\u4e0a\u624b\uff0c\u6709\u5229\u4e8e\u5feb\u901f\u7f16\u5199\u811a\u672c\u3002<\/li>\n<li>\u751f\u6001\u5b8c\u5584\uff1a\u62e5\u6709\u4e30\u5bcc\u7684\u7b2c\u4e09\u65b9\u5e93\uff0c\u5982Paramiko\u3001Fabric\u3001psutil\u7b49\uff0c\u4e3a\u8fdc\u7a0b\u8fde\u63a5\u3001\u8d44\u6e90\u76d1\u63a7\u3001\u6279\u91cf\u64cd\u4f5c\u63d0\u4f9b\u4fbf\u5229\u3002<\/li>\n<li>\u53ef\u6269\u5c55\u6027\u5f3a\uff1a\u53ef\u4ee5\u4e0e\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u6216\u7cfb\u7edf\u5de5\u5177\u7ed3\u5408\uff0c\u6784\u5efa\u7075\u6d3b\u7684\u8fd0\u7ef4\u5e73\u53f0\u3002<\/li>\n<p>\u5728\u672c\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u56f4\u7ed5\u201cPython\u81ea\u52a8\u5316\u8fd0\u7ef4\uff1a\u7f16\u5199\u81ea\u52a8\u5316\u811a\u672c\u8fdb\u884c\u670d\u52a1\u5668\u7ba1\u7406\u201d\u8fd9\u4e00\u4e3b\u9898\uff0c\u7cfb\u7edf\u4ecb\u7ecd\u5982\u4f55\u501f\u52a9Python\u8fdb\u884c\u6279\u91cf\u64cd\u4f5c\u3001\u5b9a\u65f6\u4efb\u52a1\u548c\u65e5\u5fd7\u6e05\u7406\u7b49\u81ea\u52a8\u5316\u8fd0\u7ef4\u4efb\u52a1\u3002\u6587\u7ae0\u4e0d\u4ec5\u4f1a\u7ed9\u51fa\u5927\u91cf\u7684\u793a\u4f8b\u4ee3\u7801\uff0c\u8fd8\u4f1a\u5bf9\u6bcf\u6bb5\u4ee3\u7801\u8fdb\u884c\u8be6\u5c3d\u7684\u4e2d\u6587\u6ce8\u91ca\u548c\u89e3\u91ca\uff0c\u4ee5\u5e2e\u52a9\u8bfb\u8005\u66f4\u597d\u5730\u638c\u63e1Python\u81ea\u52a8\u5316\u8fd0\u7ef4\u7684\u76f8\u5173\u6280\u672f\uff0c\u5e76\u5728\u5b9e\u9645\u751f\u4ea7\u73af\u5883\u4e2d\u5f97\u4ee5\u843d\u5730\u5b9e\u65bd\u3002<\/p>\n<p>\u63d0\u793a\uff1a\u5982\u679c\u60a8\u5bf9\u5e76\u53d1\u7f16\u7a0b\u3001\u7f51\u7edc\u534f\u8bae\u6216\u7cfb\u7edf\u7ba1\u7406\u6709\u4e00\u5b9a\u7684\u4e86\u89e3\uff0c\u5c06\u66f4\u6709\u52a9\u4e8e\u7406\u89e3\u672c\u7bc7\u5185\u5bb9\uff1b\u4f46\u5373\u4f7f\u662f\u521d\u5b66\u8005\uff0c\u4e5f\u80fd\u901a\u8fc7\u793a\u4f8b\u4ee3\u7801\u548c\u8be6\u7ec6\u89e3\u8bf4\uff0c\u9010\u6b65\u638c\u63e1\u81ea\u52a8\u5316\u8fd0\u7ef4\u811a\u672c\u7684\u7f16\u5199\u65b9\u6cd5\u3002<\/p>\n<hr>\n<h3>\u4e00\u3001Python\u5728\u8fd0\u7ef4\u81ea\u52a8\u5316\u4e2d\u7684\u89d2\u8272<\/h3>\n<p>\u5728\u4f01\u4e1a\u65e5\u5e38\u8fd0\u7ef4\u5de5\u4f5c\u4e2d\uff0c\u5e38\u89c1\u7684\u81ea\u52a8\u5316\u9700\u6c42\u5305\u62ec\uff1a<\/p>\n<li>\u6279\u91cf\u64cd\u4f5c\uff1a\u4f8b\u5982\u540c\u65f6\u5bf9\u591a\u53f0\u670d\u52a1\u5668\u5b89\u88c5\u8f6f\u4ef6\u3001\u66f4\u65b0\u914d\u7f6e\u6587\u4ef6\u6216\u6267\u884c\u91cd\u542f\u64cd\u4f5c\u3002<\/li>\n<li>\u5b9a\u65f6\u4efb\u52a1\uff1a\u4f7f\u7528\u811a\u672c\u66ff\u4ee3\u624b\u52a8\u6392\u67e5\u548c\u5904\u7406\uff0c\u5982\u5b9a\u671f\u6e05\u7406\u65e5\u5fd7\u3001\u5907\u4efd\u6570\u636e\u7b49\u3002<\/li>\n<li>\u76d1\u63a7\u548c\u62a5\u8b66\uff1a\u83b7\u53d6CPU\u3001\u5185\u5b58\u7b49\u8d44\u6e90\u4f7f\u7528\u60c5\u51b5\uff0c\u6216\u8005\u6536\u96c6\u5f02\u5e38\u65e5\u5fd7\u540e\u53d1\u9001\u62a5\u8b66\u901a\u77e5\u3002<\/li>\n<li>\u65e5\u5fd7\u7ba1\u7406\uff1a\u5b9a\u671f\u6e05\u7406\u8fc7\u671f\u65e5\u5fd7\u5e76\u5c06\u91cd\u8981\u65e5\u5fd7\u8fdb\u884c\u5f52\u6863\u6216\u5907\u4efd\u3002<\/li>\n<li>\u81ea\u52a8\u5316\u90e8\u7f72\uff1a\u5728\u6301\u7eed\u96c6\u6210\u548c\u6301\u7eed\u4ea4\u4ed8\uff08CI\/CD\uff09\u6d41\u7a0b\u4e2d\uff0c\u5b9e\u73b0\u4e00\u952e\u90e8\u7f72\u548c\u56de\u6eda\u3002<\/li>\n<p>Python\u53ef\u4ee5\u901a\u8fc7\u7b2c\u4e09\u65b9\u5e93\u6216\u539f\u751f\u529f\u80fd\uff0c\u8f7b\u677e\u5b8c\u6210\u4ee5\u4e0a\u4efb\u52a1\uff0c\u5e76\u4e14\u53ef\u6269\u5c55\u4e3a\u4e00\u6574\u5957\u81ea\u52a8\u5316\u8fd0\u7ef4\u5e73\u53f0\u3002\u4f8b\u5982\uff0c\u901a\u8fc7Paramiko\u6216Fabric\u5e93\u5b9e\u73b0SSH\u8fdc\u7a0b\u64cd\u4f5c\uff0c\u901a\u8fc7crontab\u6216schedule\u5e93\u5b9e\u73b0\u5b9a\u65f6\u4efb\u52a1\uff0c\u901a\u8fc7logging\u6a21\u5757\u5b9e\u73b0\u65e5\u5fd7\u7684\u7ba1\u7406\u4e0e\u5f52\u6863\uff0c\u914d\u5408psutil\u5e93\u76d1\u63a7\u7cfb\u7edf\u8d44\u6e90\u7b49\u3002<\/p>\n<hr>\n<h3>\u4e8c\u3001\u6279\u91cf\u5904\u7406\uff1a\u63d0\u5347\u5927\u89c4\u6a21\u670d\u52a1\u5668\u7ba1\u7406\u6548\u7387<\/h3>\n<h4>2.1 Paramiko\u4e0eFabric\uff1aSSH\u81ea\u52a8\u5316\u5229\u5668<\/h4>\n<h5>2.1.1 Paramiko\u7b80\u4ecb<\/h5>\n<p>Paramiko\u662f\u4e00\u4e2a\u7eafPython\u5b9e\u73b0\u7684SSHv2\u534f\u8bae\u5e93\uff0c\u652f\u6301\u52a0\u5bc6\u4e0e\u9a8c\u8bc1\uff0c\u53ef\u4ee5\u7528\u6765\u8fdc\u7a0b\u6267\u884c\u547d\u4ee4\u3001\u6587\u4ef6\u4e0a\u4f20\u4e0b\u8f7d\u7b49\u3002\u4f7f\u7528Paramiko\u65f6\uff0c\u5178\u578b\u7684\u6d41\u7a0b\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>\u521b\u5efaSSHClient\u5bf9\u8c61<\/li>\n<li>\u8bbe\u7f6e\u81ea\u5b9a\u4e49\u7684\u670d\u52a1\u5668\u4e3b\u673a\u5bc6\u94a5\u7b56\u7565<\/li>\n<li>\u8c03\u7528connect\u65b9\u6cd5\u8fde\u63a5\u5230\u76ee\u6807\u670d\u52a1\u5668<\/li>\n<li>\u4f7f\u7528exec_command\u6267\u884c\u8fdc\u7a0b\u547d\u4ee4<\/li>\n<li>\u901a\u8fc7\u6807\u51c6\u8f93\u5165\/\u8f93\u51fa\u901a\u9053\u83b7\u53d6\u6267\u884c\u7ed3\u679c<\/li>\n<li>\u5173\u95ed\u8fde\u63a5<\/li>\n<\/ul>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528Paramiko\u8fde\u63a5\u5230\u8fdc\u7a0b\u670d\u52a1\u5668\u5e76\u6267\u884c\u547d\u4ee4\u7684\u793a\u4f8b\u811a\u672c\uff1a<\/p>\n<p><span class=\"token comment\">#!\/usr\/bin\/env python3<\/span><br \/>\n<span class=\"token comment\"># -*- coding: utf-8 -*-<\/span><\/p>\n<p><span class=\"token keyword\">import<\/span> paramiko<\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">execute_remote_command<\/span><span class=\"token punctuation\">(<\/span>host<span class=\"token punctuation\">,<\/span> port<span class=\"token punctuation\">,<\/span> username<span class=\"token punctuation\">,<\/span> password<span class=\"token punctuation\">,<\/span> command<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">\\&#8221;\\&#8221;\\&#8221;<br \/>\n    \u5728\u8fdc\u7a0b\u670d\u52a1\u5668\u4e0a\u6267\u884c\u547d\u4ee4\u5e76\u8fd4\u56de\u8f93\u51fa\u7ed3\u679c<br \/>\n    :param host: \u670d\u52a1\u5668IP\u6216\u57df\u540d<br \/>\n    :param port: SSH\u7aef\u53e3\uff0c\u4e00\u822c\u4e3a22<br \/>\n    :param username: \u767b\u5f55\u7528\u6237\u540d<br \/>\n    :param password: \u767b\u5f55\u5bc6\u7801<br \/>\n    :param command: \u8981\u6267\u884c\u7684\u547d\u4ee4<br \/>\n    :return: \u6267\u884c\u7ed3\u679c\u5b57\u7b26\u4e32<br \/>\n    \\&#8221;\\&#8221;\\&#8221;<\/span><br \/>\n    <span class=\"token comment\"># \u521b\u5efaSSHClient\u5bf9\u8c61<\/span><br \/>\n    ssh_client <span class=\"token operator\">=<\/span> paramiko<span class=\"token punctuation\">.<\/span>SSHClient<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token comment\"># \u81ea\u52a8\u6dfb\u52a0\u76ee\u6807\u670d\u52a1\u5668\u7684\u4e3b\u673a\u5bc6\u94a5\uff08\u4e0d\u5b89\u5168\uff0c\u4ec5\u4f9b\u6d4b\u8bd5\u4f7f\u7528\uff09<\/span><br \/>\n    ssh_client<span class=\"token punctuation\">.<\/span>set_missing_host_key_policy<span class=\"token punctuation\">(<\/span>paramiko<span class=\"token punctuation\">.<\/span>AutoAddPolicy<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token comment\"># \u8fde\u63a5\u670d\u52a1\u5668<\/span><br \/>\n    ssh_client<span class=\"token punctuation\">.<\/span>connect<span class=\"token punctuation\">(<\/span>hostname<span class=\"token operator\">=<\/span>host<span class=\"token punctuation\">,<\/span> port<span class=\"token operator\">=<\/span>port<span class=\"token punctuation\">,<\/span> username<span class=\"token operator\">=<\/span>username<span class=\"token punctuation\">,<\/span> password<span class=\"token operator\">=<\/span>password<span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\"># \u6267\u884c\u547d\u4ee4<\/span><br \/>\n    stdin<span class=\"token punctuation\">,<\/span> stdout<span class=\"token punctuation\">,<\/span> stderr <span class=\"token operator\">=<\/span> ssh_client<span class=\"token punctuation\">.<\/span>exec_command<span class=\"token punctuation\">(<\/span>command<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token comment\"># \u83b7\u53d6\u6267\u884c\u7ed3\u679c<\/span><br \/>\n    result_out <span class=\"token operator\">=<\/span> stdout<span class=\"token punctuation\">.<\/span>read<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span>decode<span class=\"token punctuation\">(<\/span><span class=\"token string\">\\&#8217;utf-8\\&#8217;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    result_err <span class=\"token operator\">=<\/span> stderr<span class=\"token punctuation\">.<\/span>read<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span>decode<span class=\"token punctuation\">(<\/span><span class=\"token string\">\\&#8217;utf-8\\&#8217;<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token comment\"># \u5173\u95ed\u8fde\u63a5<\/span><br \/>\n    ssh_client<span class=\"token punctuation\">.<\/span>close<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>    <span class=\"token keyword\">if<\/span> result_err<span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> <span class=\"token string-interpolation\"><span class=\"token string\">f\\&#8221;Error: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<br \/>\n     <\/span>result_err<span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">\\&#8221;<\/span><\/span><br \/>\n    <span class=\"token keyword\">else<\/span><span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token keyword\">return<\/span> result_out<\/p>\n<p><span class=\"token keyword\">if<\/span> __name__ <span class=\"token operator\">==<\/span> <span class=\"token string\">\\&#8221;__main__\\&#8221;<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token comment\"># \u6d4b\u8bd5\u8fde\u63a5<\/span><br \/>\n    host <span class=\"token operator\">=<\/span> <span class=\"token string\">\\&#8221;192.168.0.100\\&#8221;<\/span><br \/>\n    port <span class=\"token operator\">=<\/span> <span class=\"token number\">22<\/span><br \/>\n    username <span class=\"token operator\">=<\/span> <span class=\"token string\">\\&#8221;root\\&#8221;<\/span><br \/>\n    password <span class=\"token operator\">=<\/span> <span class=\"token string\">\\&#8221;123456\\&#8221;<\/span><br \/>\n    command <span class=\"token operator\">=<\/span> <span class=\"token string\">\\&#8221;uname -a\\&#8221;<\/span>  <span class=\"token comment\"># \u67e5\u770b\u64cd\u4f5c\u7cfb\u7edf\u4fe1\u606f<\/span><\/p>\n<p>    output <span class=\"token operator\">=<\/span> execute_remote_command<span class=\"token punctuation\">(<\/span>host<span class=\"token punctuation\">,<\/span> port<span class=\"token punctuation\">,<\/span> username<span class=\"token punctuation\">,<\/span> password<span class=\"token punctuation\">,<\/span> command<span class=\"token punctuation\">)<\/span><br \/>\n    <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string\">\\&#8221;\u8fdc\u7a0b\u6267\u884c\u7ed3\u679c:\\\\n\\&#8221;<\/span><span class=\"token punctuation\">,<\/span> output<span class=\"token punctuation\">)<\/span><\/p>\n<h6>\u4ee3\u7801\u89e3\u91ca<\/h6>\n<li>Paramiko\u5e93\u7684\u4f7f\u7528\uff1a\u5148\u521b\u5efaSSHClient\u5bf9\u8c61\uff0c\u7136\u540e\u4f7f\u7528set_missing_host_key_policy\u8bbe\u7f6e\u4e3a\u81ea\u52a8\u6dfb\u52a0\u670d\u52a1\u5668\u6307\u7eb9\u3002<\/li>\n<li>\u8fde\u63a5\u670d\u52a1\u5668\uff1a\u901a\u8fc7connect\u65b9\u6cd5\u4f20\u5165\u670d\u52a1\u5668IP\u3001\u7aef\u53e3\u3001\u7528\u6237\u540d\u548c\u5bc6\u7801\u3002<\/li>\n<li>\u547d\u4ee4\u6267\u884c\uff1a\u4f7f\u7528exec_command\uff0c\u53ef\u83b7\u53d6\u6807\u51c6\u8f93\u5165\u3001\u6807\u51c6\u8f93\u51fa\u548c\u6807\u51c6\u9519\u8bef\u3002<\/li>\n<li>\u7ed3\u679c\u5904\u7406\uff1a\u5c06\u8f93\u51fa\u548c\u9519\u8bef\u6d88\u606f\u5206\u522b\u8bfb\u53d6\u5e76\u8f6c\u6362\u4e3aUTF-8\u5b57\u7b26\u4e32\u3002<\/li>\n<li>\u8fde\u63a5\u5173\u95ed\uff1a\u64cd\u4f5c\u5b8c\u6210\u540e\u8c03\u7528close\uff0c\u91ca\u653e\u8fde\u63a5\u8d44\u6e90\u3002<\/li>\n<h5>2.1.2 Fabric\u7b80\u4ecb<\/h5>\n<p>Fabric\u57fa\u4e8eParamiko\u5f00\u53d1\uff0c\u7b80\u5316\u4e86\u591a\u670d\u52a1\u5668\u6279\u91cf\u64cd\u4f5c\u7684\u6d41\u7a0b\uff0c\u5c24\u5176\u9002\u7528\u4e8e\u81ea\u52a8\u5316\u90e8\u7f72\u548c\u6279\u91cf\u547d\u4ee4\u6267\u884c\u3002\u5b83\u63d0\u4f9b\u4e86\u66f4\u9ad8\u5c42\u6b21\u7684API\uff0c\u4f8b\u5982fab\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u53ef\u4ee5\u5728fabfile.py\u4e2d\u5b9a\u4e49\u4e00\u7cfb\u5217\u4efb\u52a1\uff0c\u7136\u540e\u5728\u547d\u4ee4\u884c\u4e2d\u901a\u8fc7fab \u4efb\u52a1\u540d\u6267\u884c\u3002\u4e0b\u9762\u5c55\u793a\u4e00\u4e2a\u7b80\u5355\u7684Fabric\u793a\u4f8b\uff0c\u7528\u4e8e\u6279\u91cf\u83b7\u53d6\u670d\u52a1\u5668\u7684\u64cd\u4f5c\u7cfb\u7edf\u4fe1\u606f\u3002<\/p>\n<p>\u5148\u5b89\u88c5Fabric\uff1a<\/p>\n<p>pip <span class=\"token function\">install<\/span> <span class=\"token assign-left variable\">fabric<\/span><span class=\"token operator\">==<\/span><span class=\"token number\">2.6<\/span>.0<\/p>\n<p>\u6ce8\u610f\uff1aFabric 2.x\u548c1.x\u7248\u672cAPI\u5dee\u5f02\u8f83\u5927\uff0c\u793a\u4f8b\u57fa\u4e8e2.x\u7248\u672c\u3002<\/p>\n<p>\u5728\u9879\u76ee\u76ee\u5f55\u4e0b\u521b\u5efafabfile.py\uff0c\u793a\u4f8b\u5982\u4e0b\uff1a<\/p>\n<p><span class=\"token comment\">#!\/usr\/bin\/env python3<\/span><br \/>\n<span class=\"token comment\"># -*- coding: utf-8 -*-<\/span><\/p>\n<p><span class=\"token keyword\">from<\/span> fabric <span class=\"token keyword\">import<\/span> Connection<\/p>\n<p><span class=\"token comment\"># \u5b9a\u4e49\u670d\u52a1\u5668\u5217\u8868<\/span><br \/>\nservers <span class=\"token operator\">=<\/span> <span class=\"token punctuation\">[<\/span><br \/>\n    <span class=\"token punctuation\">{<br \/>\n   <\/span><span class=\"token string\">\\&#8221;host\\&#8221;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">\\&#8221;192.168.0.101\\&#8221;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">\\&#8221;user\\&#8221;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">\\&#8221;root\\&#8221;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">\\&#8221;connect_kwargs\\&#8221;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">{<br \/>\n   <\/span><span class=\"token string\">\\&#8221;password\\&#8221;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">\\&#8221;123456\\&#8221;<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">,<\/span><br \/>\n    <span class=\"token punctuation\">{<br \/>\n   <\/span><span class=\"token string\">\\&#8221;host\\&#8221;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">\\&#8221;192.168.0.102\\&#8221;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">\\&#8221;user\\&#8221;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">\\&#8221;root\\&#8221;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">\\&#8221;connect_kwargs\\&#8221;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token punctuation\">{<br \/>\n   <\/span><span class=\"token string\">\\&#8221;password\\&#8221;<\/span><span class=\"token punctuation\">:<\/span> <span class=\"token string\">\\&#8221;123456\\&#8221;<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">}<\/span><span class=\"token punctuation\">,<\/span><br \/>\n<span class=\"token punctuation\">]<\/span><\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">get_os_info<\/span><span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">\\&#8221;\\&#8221;\\&#8221;<br \/>\n    \u83b7\u53d6\u670d\u52a1\u5668\u64cd\u4f5c\u7cfb\u7edf\u4fe1\u606f<br \/>\n    \\&#8221;\\&#8221;\\&#8221;<\/span><br \/>\n    <span class=\"token keyword\">for<\/span> srv <span class=\"token keyword\">in<\/span> servers<span class=\"token punctuation\">:<\/span><br \/>\n        <span class=\"token comment\"># \u521b\u5efa\u8fde\u63a5<\/span><br \/>\n        conn <span class=\"token operator\">=<\/span> Connection<span class=\"token punctuation\">(<\/span><span class=\"token operator\">**<\/span>srv<span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f\\&#8221;\u8fde\u63a5\u5230\u670d\u52a1\u5668: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<br \/>\n     <\/span>srv<span class=\"token punctuation\">[<\/span><span class=\"token string\">\\&#8217;host\\&#8217;<\/span><span class=\"token punctuation\">]<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">\\&#8221;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n        result <span class=\"token operator\">=<\/span> conn<span class=\"token punctuation\">.<\/span>run<span class=\"token punctuation\">(<\/span><span class=\"token string\">\\&#8221;uname -a\\&#8221;<\/span><span class=\"token punctuation\">,<\/span> hide<span class=\"token operator\">=<\/span><span class=\"token boolean\">True<\/span><span class=\"token punctuation\">)<\/span><br \/>\n        <span class=\"token keyword\">print<\/span><span class=\"token punctuation\">(<\/span><span class=\"token string-interpolation\"><span class=\"token string\">f\\&#8221;\u64cd\u4f5c\u7cfb\u7edf\u4fe1\u606f: <\/span><span class=\"token interpolation\"><span class=\"token punctuation\">{<br \/>\n     <\/span>result<span class=\"token punctuation\">.<\/span>stdout<span class=\"token punctuation\">.<\/span>strip<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">}<\/span><\/span><span class=\"token string\">\\&#8221;<\/span><\/span><span class=\"token punctuation\">)<\/span><br \/>\n        conn<span class=\"token punctuation\">.<\/span>close<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><\/p>\n<p>\u7136\u540e\u5728\u547d\u4ee4\u884c\u4e2d\u6267\u884c\uff1a<\/p>\n<p>fab get_os_info<\/p>\n<h6>\u4ee3\u7801\u89e3\u91ca<\/h6>\n<li>\u670d\u52a1\u5668\u5217\u8868\uff1a\u5b9a\u4e49\u4e00\u4e2aPython\u5217\u8868\uff0c\u5b58\u50a8\u591a\u53f0\u670d\u52a1\u5668\u7684\u8fde\u63a5\u4fe1\u606f\uff0c\u5305\u62ec\u4e3b\u673a\u540d\u3001\u7528\u6237\u53ca\u5bc6\u7801\u3002<\/li>\n<li>Connection\u5bf9\u8c61\uff1aFabric\u63d0\u4f9b\u4e86Connection\u5bf9\u8c61\uff0c\u7528\u4e8e\u5efa\u7acbSSH\u4f1a\u8bdd\u3002<\/li>\n<li>\u6279\u91cf\u6267\u884c\uff1a\u5faa\u73af\u670d\u52a1\u5668\u5217\u8868\uff0c\u6bcf\u6b21\u521b\u5efaConnection\uff0c\u6267\u884c\u547d\u4ee4\u5e76\u6253\u5370\u7ed3\u679c\u3002<\/li>\n<li>\u5173\u95ed\u8fde\u63a5\uff1a\u5b8c\u6210\u64cd\u4f5c\u540e\u8c03\u7528close\uff0c\u907f\u514d\u8d44\u6e90\u6cc4\u6f0f\u3002<\/li>\n<p>\u65e0\u8bba\u662fParamiko\u8fd8\u662fFabric\uff0c\u90fd\u80fd\u6781\u5927\u5730\u65b9\u4fbf\u6279\u91cf\u5904\u7406\u4efb\u52a1\u3002\u540e\u6587\u4e2d\uff0c\u6211\u4eec\u8fd8\u4f1a\u8fdb\u4e00\u6b65\u7ed3\u5408\u5b9a\u65f6\u4efb\u52a1\u4e0e\u65e5\u5fd7\u7ba1\u7406\u8fdb\u884c\u7efc\u5408\u793a\u4f8b\u3002<\/p>\n<hr>\n<h4>2.2 \u5e76\u53d1\u6279\u91cf\u5904\u7406<\/h4>\n<p>\u5728\u5927\u89c4\u6a21\u96c6\u7fa4\u73af\u5883\u4e0b\uff0c\u4f9d\u6b21\u8fde\u63a5\u6bcf\u53f0\u670d\u52a1\u5668\u7684\u65b9\u5f0f\u6548\u7387\u4e0d\u9ad8\u3002\u4e3a\u63d0\u9ad8\u6279\u91cf\u5904\u7406\u901f\u5ea6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5e76\u53d1\u6216\u591a\u7ebf\u7a0b\u65b9\u5f0f\uff0c\u540c\u65f6\u8fde\u63a5\u591a\u53f0\u670d\u52a1\u5668\u5e76\u6267\u884c\u64cd\u4f5c\u3002<\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u57fa\u4e8eparamiko\u548cPython\u7684ThreadPoolExecutor\u5b9e\u73b0\u591a\u7ebf\u7a0b\u5e76\u53d1\u6279\u91cf\u7ba1\u7406\uff1a<\/p>\n<p><span class=\"token comment\">#!\/usr\/bin\/env python3<\/span><br \/>\n<span class=\"token comment\"># -*- coding: utf-8 -*-<\/span><\/p>\n<p><span class=\"token keyword\">import<\/span> paramiko<br \/>\n<span class=\"token keyword\">import<\/span> concurrent<span class=\"token punctuation\">.<\/span>futures<\/p>\n<p><span class=\"token keyword\">def<\/span> <span class=\"token function\">execute_command<\/span><span class=\"token punctuation\">(<\/span>host<span class=\"token punctuation\">,<\/span> username<span class=\"token punctuation\">,<\/span> password<span class=\"token punctuation\">,<\/span> command<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">:<\/span><br \/>\n    <span class=\"token triple-quoted-string string\">\\&#8221;\\&#8221;\\&#8221;<br \/>\n    \u5728\u5355\u53f0\u670d\u52a1\u5668\u4e0a\u6267\u884c\u547d\u4ee4<br \/>\n    \\&#8221;\\&#8221;\\&#8221;<\/span><br \/>\n    ssh_client <span class=\"token operator\">=<\/span> paramiko<span class=\"token punctuation\">.<\/span>SSHClient<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    ssh_client<span class=\"token punctuation\">.<\/span>set_missing_host_key_policy<span class=\"token punctuation\">(<\/span>paramiko<span class=\"token punctuation\">.<\/span>AutoAddPolicy<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    ssh_client<span class=\"token punctuation\">.<\/span>connect<span class=\"token punctuation\">(<\/span>hostname<span class=\"token operator\">=<\/span>host<span class=\"token punctuation\">,<\/span> port<span class=\"token operator\">=<\/span><span class=\"token number\">22<\/span><span class=\"token punctuation\">,<\/span> username<span class=\"token operator\">=<\/span>username<span class=\"token punctuation\">,<\/span> password<span class=\"token operator\">=<\/span>password<span class=\"token punctuation\">)<\/span><br \/>\n    stdin<span class=\"token punctuation\">,<\/span> stdout<span class=\"token punctuation\">,<\/span> stderr <span class=\"token operator\">=<\/span> ssh_client<span class=\"token punctuation\">.<\/span>exec_command<span class=\"token punctuation\">(<\/span>command<span class=\"token punctuation\">)<\/span><br \/>\n    result_out <span class=\"token operator\">=<\/span> stdout<span class=\"token punctuation\">.<\/span>read<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span>decode<span class=\"token punctuation\">(<\/span><span class=\"token string\">\\&#8217;utf-8\\&#8217;<\/span><span class=\"token punctuation\">)<\/span><br \/>\n    result_err <span class=\"token operator\">=<\/span> stderr<span class=\"token punctuation\">.<\/span>read<span class=\"token punctuation\">(<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">.<\/span>decode<span class=\"token punctuation\">(<\/span><span class=\"token string\">\\&#8217;utf-8\\&#8217;<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.3k\u6b21\uff0c\u70b9\u8d5e24\u6b21\uff0c\u6536\u85cf14\u6b21\u3002\u5728\u4e92\u8054\u7f51\u548c\u4e91\u8ba1\u7b97\u9ad8\u901f\u53d1\u5c55\u7684\u4eca\u5929\uff0c\u670d\u52a1\u5668\u6570\u91cf\u7684\u6307\u6570\u589e\u957f\u4f7f\u5f97\u624b\u52a8\u8fd0\u7ef4\u548c\u7ba1\u7406\u53d8\u5f97\u5f02\u5e38\u7e41\u7410\u3002Python\u51ed\u501f\u5176\u5f3a\u5927\u7684\u53ef\u8bfb\u6027\u548c\u4e30\u5bcc\u7684\u751f\u6001\u7cfb\u7edf\uff0c\u6210\u4e3a\u5b9e\u73b0\u81ea\u52a8\u5316\u8fd0\u7ef4\u7684\u7406\u60f3\u8bed\u8a00\u3002\u672c\u6587\u4ee5\u201cPython\u81ea\u52a8\u5316\u8fd0\u7ef4\uff1a\u7f16\u5199\u81ea\u52a8\u5316\u811a\u672c\u8fdb\u884c\u670d\u52a1\u5668\u7ba1\u7406\u201d\u4e3a\u4e3b\u9898\uff0c\u6df1\u5165\u63a2\u8ba8\u4e86\u5982\u4f55\u5229\u7528Python\u5728\u6279\u91cf\u5904\u7406\u3001\u5b9a\u65f6\u4efb\u52a1\u548c\u65e5\u5fd7\u6e05\u7406\u7b49\u65b9\u9762\u89e3\u653e\u8fd0\u7ef4\u4eba\u5458\u7684\u53cc\u624b\u3002\u6587\u7ae0\u4eceSSH\u8fde\u63a5\u3001\u6279\u91cf\u90e8\u7f72\u811a\u672c\u5230\u65e5\u5fd7\u5f52\u6863\u3001\u81ea\u52a8\u5316\u62a5\u8b66\u7b49\u591a\u4e2a\u89d2\u5ea6\u8fdb\u884c\u4e86\u8be6\u7ec6\u9610\u8ff0\u4e0e\u4ee3\u7801\u793a\u4f8b\uff0c\u5e76\u5206\u4eab\u4e86\u5e38\u89c1\u7684\u6700\u4f73\u5b9e\u8df5\u548c\u6027\u80fd\u4f18\u5316\u601d\u8def\u3002\u901a\u8fc7\u9605\u8bfb\u672c\u6587\uff0c\u8bfb\u8005\u53ef\u4ee5\u5feb\u901f\u638c\u63e1Python\u81ea\u52a8\u5316\u8fd0\u7ef4\u7684\u6838\u5fc3\u6280\u80fd\uff0c\u8fdb\u4e00_opencv\u4e4b\u8fd0\u7ef4\u81ea\u52a8\u5316<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[81,889,395,44],"topic":[],"class_list":{"0":"post-14286","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"hentry","6":"category-server","7":"tag-python","9":"tag-395","10":"tag-44"},"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Python\u81ea\u52a8\u5316\u8fd0\u7ef4\uff1a\u4e00\u952e\u638c\u63a7\u670d\u52a1\u5668\u7684\u9ad8\u6548\u4e4b\u9053 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/14286.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Python\u81ea\u52a8\u5316\u8fd0\u7ef4\uff1a\u4e00\u952e\u638c\u63a7\u670d\u52a1\u5668\u7684\u9ad8\u6548\u4e4b\u9053 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.3k\u6b21\uff0c\u70b9\u8d5e24\u6b21\uff0c\u6536\u85cf14\u6b21\u3002\u5728\u4e92\u8054\u7f51\u548c\u4e91\u8ba1\u7b97\u9ad8\u901f\u53d1\u5c55\u7684\u4eca\u5929\uff0c\u670d\u52a1\u5668\u6570\u91cf\u7684\u6307\u6570\u589e\u957f\u4f7f\u5f97\u624b\u52a8\u8fd0\u7ef4\u548c\u7ba1\u7406\u53d8\u5f97\u5f02\u5e38\u7e41\u7410\u3002Python\u51ed\u501f\u5176\u5f3a\u5927\u7684\u53ef\u8bfb\u6027\u548c\u4e30\u5bcc\u7684\u751f\u6001\u7cfb\u7edf\uff0c\u6210\u4e3a\u5b9e\u73b0\u81ea\u52a8\u5316\u8fd0\u7ef4\u7684\u7406\u60f3\u8bed\u8a00\u3002\u672c\u6587\u4ee5\u201cPython\u81ea\u52a8\u5316\u8fd0\u7ef4\uff1a\u7f16\u5199\u81ea\u52a8\u5316\u811a\u672c\u8fdb\u884c\u670d\u52a1\u5668\u7ba1\u7406\u201d\u4e3a\u4e3b\u9898\uff0c\u6df1\u5165\u63a2\u8ba8\u4e86\u5982\u4f55\u5229\u7528Python\u5728\u6279\u91cf\u5904\u7406\u3001\u5b9a\u65f6\u4efb\u52a1\u548c\u65e5\u5fd7\u6e05\u7406\u7b49\u65b9\u9762\u89e3\u653e\u8fd0\u7ef4\u4eba\u5458\u7684\u53cc\u624b\u3002\u6587\u7ae0\u4eceSSH\u8fde\u63a5\u3001\u6279\u91cf\u90e8\u7f72\u811a\u672c\u5230\u65e5\u5fd7\u5f52\u6863\u3001\u81ea\u52a8\u5316\u62a5\u8b66\u7b49\u591a\u4e2a\u89d2\u5ea6\u8fdb\u884c\u4e86\u8be6\u7ec6\u9610\u8ff0\u4e0e\u4ee3\u7801\u793a\u4f8b\uff0c\u5e76\u5206\u4eab\u4e86\u5e38\u89c1\u7684\u6700\u4f73\u5b9e\u8df5\u548c\u6027\u80fd\u4f18\u5316\u601d\u8def\u3002\u901a\u8fc7\u9605\u8bfb\u672c\u6587\uff0c\u8bfb\u8005\u53ef\u4ee5\u5feb\u901f\u638c\u63e1Python\u81ea\u52a8\u5316\u8fd0\u7ef4\u7684\u6838\u5fc3\u6280\u80fd\uff0c\u8fdb\u4e00_opencv\u4e4b\u8fd0\u7ef4\u81ea\u52a8\u5316\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/14286.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2025-04-18T13:02:52+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/14286.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/14286.html\",\"name\":\"Python\u81ea\u52a8\u5316\u8fd0\u7ef4\uff1a\u4e00\u952e\u638c\u63a7\u670d\u52a1\u5668\u7684\u9ad8\u6548\u4e4b\u9053 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2025-04-18T13:02:52+00:00\",\"dateModified\":\"2025-04-18T13:02:52+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/14286.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/14286.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/14286.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Python\u81ea\u52a8\u5316\u8fd0\u7ef4\uff1a\u4e00\u952e\u638c\u63a7\u670d\u52a1\u5668\u7684\u9ad8\u6548\u4e4b\u9053\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Python\u81ea\u52a8\u5316\u8fd0\u7ef4\uff1a\u4e00\u952e\u638c\u63a7\u670d\u52a1\u5668\u7684\u9ad8\u6548\u4e4b\u9053 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/14286.html","og_locale":"zh_CN","og_type":"article","og_title":"Python\u81ea\u52a8\u5316\u8fd0\u7ef4\uff1a\u4e00\u952e\u638c\u63a7\u670d\u52a1\u5668\u7684\u9ad8\u6548\u4e4b\u9053 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u6587\u7ae0\u6d4f\u89c8\u9605\u8bfb1.3k\u6b21\uff0c\u70b9\u8d5e24\u6b21\uff0c\u6536\u85cf14\u6b21\u3002\u5728\u4e92\u8054\u7f51\u548c\u4e91\u8ba1\u7b97\u9ad8\u901f\u53d1\u5c55\u7684\u4eca\u5929\uff0c\u670d\u52a1\u5668\u6570\u91cf\u7684\u6307\u6570\u589e\u957f\u4f7f\u5f97\u624b\u52a8\u8fd0\u7ef4\u548c\u7ba1\u7406\u53d8\u5f97\u5f02\u5e38\u7e41\u7410\u3002Python\u51ed\u501f\u5176\u5f3a\u5927\u7684\u53ef\u8bfb\u6027\u548c\u4e30\u5bcc\u7684\u751f\u6001\u7cfb\u7edf\uff0c\u6210\u4e3a\u5b9e\u73b0\u81ea\u52a8\u5316\u8fd0\u7ef4\u7684\u7406\u60f3\u8bed\u8a00\u3002\u672c\u6587\u4ee5\u201cPython\u81ea\u52a8\u5316\u8fd0\u7ef4\uff1a\u7f16\u5199\u81ea\u52a8\u5316\u811a\u672c\u8fdb\u884c\u670d\u52a1\u5668\u7ba1\u7406\u201d\u4e3a\u4e3b\u9898\uff0c\u6df1\u5165\u63a2\u8ba8\u4e86\u5982\u4f55\u5229\u7528Python\u5728\u6279\u91cf\u5904\u7406\u3001\u5b9a\u65f6\u4efb\u52a1\u548c\u65e5\u5fd7\u6e05\u7406\u7b49\u65b9\u9762\u89e3\u653e\u8fd0\u7ef4\u4eba\u5458\u7684\u53cc\u624b\u3002\u6587\u7ae0\u4eceSSH\u8fde\u63a5\u3001\u6279\u91cf\u90e8\u7f72\u811a\u672c\u5230\u65e5\u5fd7\u5f52\u6863\u3001\u81ea\u52a8\u5316\u62a5\u8b66\u7b49\u591a\u4e2a\u89d2\u5ea6\u8fdb\u884c\u4e86\u8be6\u7ec6\u9610\u8ff0\u4e0e\u4ee3\u7801\u793a\u4f8b\uff0c\u5e76\u5206\u4eab\u4e86\u5e38\u89c1\u7684\u6700\u4f73\u5b9e\u8df5\u548c\u6027\u80fd\u4f18\u5316\u601d\u8def\u3002\u901a\u8fc7\u9605\u8bfb\u672c\u6587\uff0c\u8bfb\u8005\u53ef\u4ee5\u5feb\u901f\u638c\u63e1Python\u81ea\u52a8\u5316\u8fd0\u7ef4\u7684\u6838\u5fc3\u6280\u80fd\uff0c\u8fdb\u4e00_opencv\u4e4b\u8fd0\u7ef4\u81ea\u52a8\u5316","og_url":"https:\/\/www.wsisp.com\/helps\/14286.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2025-04-18T13:02:52+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"2 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/14286.html","url":"https:\/\/www.wsisp.com\/helps\/14286.html","name":"Python\u81ea\u52a8\u5316\u8fd0\u7ef4\uff1a\u4e00\u952e\u638c\u63a7\u670d\u52a1\u5668\u7684\u9ad8\u6548\u4e4b\u9053 - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2025-04-18T13:02:52+00:00","dateModified":"2025-04-18T13:02:52+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/14286.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/14286.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/14286.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"Python\u81ea\u52a8\u5316\u8fd0\u7ef4\uff1a\u4e00\u952e\u638c\u63a7\u670d\u52a1\u5668\u7684\u9ad8\u6548\u4e4b\u9053"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/14286","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=14286"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/14286\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=14286"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=14286"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=14286"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=14286"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}