{"id":18097,"date":"2024-11-18T14:34:33","date_gmt":"2024-11-18T06:34:33","guid":{"rendered":"https:\/\/fwq.ai\/blog\/18097\/"},"modified":"2024-11-18T14:34:33","modified_gmt":"2024-11-18T06:34:33","slug":"linux%e6%80%8e%e4%b9%88%e8%bf%90%e8%a1%8cpython%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/18097\/","title":{"rendered":"linux\u600e\u4e48\u8fd0\u884cpython\u6587\u4ef6"},"content":{"rendered":"<blockquote><p>\n  \u5728 linux \u4e2d\u8fd0\u884c python \u6587\u4ef6\uff1a1. \u5b89\u88c5 python\uff1b2. \u6253\u5f00\u7ec8\u7aef\u5e76\u5bfc\u822a\u5230\u6587\u4ef6\u76ee\u5f55\uff1b3. \u4f7f\u7528 python \u89e3\u91ca\u5668\u8fd0\u884c\u6587\u4ef6\uff08\u53ef\u4f7f\u7528 &#8220;-m&#8221; \u9009\u9879\u6216\u76f4\u63a5\u6307\u5b9a\u6587\u4ef6\u540d\uff09\uff1b4. \u9a8c\u8bc1\u8f93\u51fa\uff1b5. \u53ef\u9009\uff1a\u521b\u5efa\u53ef\u6267\u884c\u6587\u4ef6\u6216\u4f7f\u7528\u7ba1\u9053\u91cd\u5b9a\u5411\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/03\/2024060310302173709.jpg\" class=\"aligncenter\" title=\"linux\u600e\u4e48\u8fd0\u884cpython\u6587\u4ef6\u63d2\u56fe\" alt=\"linux\u600e\u4e48\u8fd0\u884cpython\u6587\u4ef6\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728 Linux \u4e2d\u8fd0\u884c Python \u6587\u4ef6<\/strong><\/p>\n<p><strong>\u6b65\u9aa4 1\uff1a\u5b89\u88c5 Python\uff08\u5982\u679c\u5c1a\u672a\u5b89\u88c5\uff09<\/strong><\/p>\n<pre>sudo apt-get update\nsudo apt-get install python3<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6b65\u9aa4 2\uff1a\u6253\u5f00\u7ec8\u7aef\u5e76\u5bfc\u822a\u5230\u6587\u4ef6\u76ee\u5f55<\/strong><\/p>\n<pre>cd \/path\/to\/directory<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6b65\u9aa4 3\uff1a\u4f7f\u7528 Python \u89e3\u91ca\u5668\u8fd0\u884c\u6587\u4ef6<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a<\/p>\n<ul>\n<li><strong>\u4f7f\u7528 -m \u9009\u9879\uff1a<\/strong><\/li>\n<\/ul>\n<pre>python3 -m script<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d &#8220;script&#8221; \u662f\u60a8\u8981\u8fd0\u884c\u7684\u6587\u4ef6\u540d\u3002<\/p>\n<ul>\n<li><strong>\u76f4\u63a5\u6307\u5b9a\u6587\u4ef6\u540d\uff1a<\/strong><\/li>\n<\/ul>\n<pre>python3 script.py<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6b65\u9aa4 4\uff1a\u9a8c\u8bc1\u8f93\u51fa<\/strong><\/p>\n<p>\u6587\u4ef6\u5e94\u8be5\u6309\u9884\u671f\u8fd0\u884c\uff0c\u60a8\u5c06\u5728\u7ec8\u7aef\u4e2d\u770b\u5230\u8f93\u51fa\u3002<\/p>\n<p><strong>\u5176\u4ed6\u65b9\u6cd5\uff08\u53ef\u9009\uff09<\/strong><\/p>\n<ul>\n<li><strong>\u521b\u5efa\u53ef\u6267\u884c\u6587\u4ef6\uff1a<\/strong><\/li>\n<\/ul>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u521b\u5efa\u53ef\u6267\u884c\u6587\u4ef6\uff1a<\/p>\n<pre>chmod +x script.py<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u7136\u540e\u53ef\u4ee5\u4f7f\u7528 &#8220;.\/script.py&#8221; \u8fd0\u884c\u5b83\u3002<\/p>\n<ul>\n<li><strong>\u4f7f\u7528\u7ba1\u9053\u91cd\u5b9a\u5411\uff1a<\/strong><\/li>\n<\/ul>\n<p>\u60a8\u53ef\u4ee5\u5c06\u6587\u4ef6\u8f93\u51fa\u91cd\u5b9a\u5411\u5230\u53e6\u4e00\u4e2a\u547d\u4ee4\uff0c\u4f8b\u5982\uff1a<\/p>\n<pre>python3 script.py | grep \"pattern\"<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4f1a\u5c06\u811a\u672c\u7684\u8f93\u51fa\u901a\u8fc7 &#8220;grep&#8221; \u547d\u4ee4\u8fdb\u884c\u8fc7\u6ee4\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u8fd0\u884c\u6587\u4ef6\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 linux \u4e2d\u8fd0\u884c python \u6587\u4ef6\uff1a1. \u5b89\u88c5 python\uff1b2. \u6253\u5f00\u7ec8\u7aef\u5e76\u5bfc\u822a\u5230\u6587\u4ef6\u76ee\u5f55\uff1b3. \u4f7f\u7528 python \u89e3\u91ca\u5668\u8fd0\u884c\u6587\u4ef6\uff08\u53ef\u4f7f\u7528 &#8220;-m&#8221; \u9009\u9879\u6216\u76f4\u63a5\u6307\u5b9a\u6587\u4ef6\u540d\uff09\uff1b4. \u9a8c\u8bc1\u8f93\u51fa\uff1b5. \u53ef\u9009\uff1a\u521b\u5efa\u53ef\u6267\u884c\u6587\u4ef6\u6216\u4f7f\u7528\u7ba1\u9053\u91cd\u5b9a\u5411\u3002 \u5728 Linux \u4e2d\u8fd0\u884c Python \u6587\u4ef6 \u6b65\u9aa4 1\uff1a\u5b89\u88c5 Python\uff08\u5982\u679c\u5c1a\u672a\u5b89\u88c5\uff09 sudo apt-get update sudo apt-get install python3 \u767b\u5f55\u540e\u590d\u5236 \u6b65\u9aa4 2\uff1a\u6253\u5f00\u7ec8\u7aef\u5e76\u5bfc\u822a\u5230\u6587\u4ef6\u76ee\u5f55 cd \/path\/to\/directory \u767b\u5f55\u540e\u590d\u5236 \u6b65\u9aa4 3\uff1a\u4f7f\u7528 Python \u89e3\u91ca\u5668\u8fd0\u884c\u6587\u4ef6 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u6709\u4e24\u79cd\u65b9\u6cd5\uff1a \u4f7f\u7528 -m \u9009\u9879\uff1a python3 -m script \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d &#8220;script&#8221; \u662f\u60a8\u8981\u8fd0\u884c\u7684\u6587\u4ef6\u540d\u3002 \u76f4\u63a5\u6307\u5b9a\u6587\u4ef6\u540d\uff1a python3 script.py [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-18097","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18097","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=18097"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/18097\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=18097"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=18097"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=18097"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}