{"id":1123014,"date":"2025-01-08T19:28:05","date_gmt":"2025-01-08T11:28:05","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1123014.html"},"modified":"2025-01-08T19:28:08","modified_gmt":"2025-01-08T11:28:08","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8nano%e6%9d%bf%e4%b8%8a%e6%89%93%e5%bc%80python3","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1123014.html","title":{"rendered":"\u5982\u4f55\u5728nano\u677f\u4e0a\u6253\u5f00python3"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25084642\/ac5b27fb-9b37-4765-81e0-88da5e4fb658.webp\" alt=\"\u5982\u4f55\u5728nano\u677f\u4e0a\u6253\u5f00python3\" \/><\/p>\n<p><p> <strong>\u5728nano\u677f\u4e0a\u6253\u5f00Python3\u7684\u65b9\u6cd5\u6709\uff1a\u5728\u547d\u4ee4\u884c\u8f93\u5165<code>python3<\/code>\u3001\u4f7f\u7528<code>nano<\/code>\u547d\u4ee4\u7f16\u8f91Python\u6587\u4ef6\u3001\u5b89\u88c5\u5fc5\u8981\u7684Python\u6a21\u5757\u3002<\/strong> \u5728\u8fd9\u4e2a\u8fc7\u7a0b\u4e2d\uff0c\u4f60\u9700\u8981\u786e\u4fdd\u4f60\u5df2\u7ecf\u5728\u7cfb\u7edf\u4e2d\u5b89\u88c5\u4e86Python3\uff0c\u5e76\u4e14\u4e86\u89e3\u4e00\u4e9b\u57fa\u672c\u7684\u547d\u4ee4\u884c\u64cd\u4f5c\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u5728nano\u677f\u4e0a\u6253\u5f00Python3\u5e76\u8fdb\u884c\u57fa\u672c\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u5b89\u88c5Python3<\/h2>\n<\/p>\n<p><h3>1. \u786e\u8ba4\u7cfb\u7edf\u4e2d\u5df2\u6709Python3<\/h3>\n<\/p>\n<p><p>\u5728\u5927\u591a\u6570\u73b0\u4ee3Linux\u53d1\u884c\u7248\u4e2d\uff0cPython3\u901a\u5e38\u662f\u9884\u88c5\u7684\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u786e\u8ba4Python3\u662f\u5426\u5df2\u7ecf\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u8f93\u51fa\u7c7b\u4f3c\u4e8e<code>Python 3.x.x<\/code>\uff0c\u90a3\u4e48\u8bf4\u660ePython3\u5df2\u7ecf\u5b89\u88c5\u6210\u529f\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u5305\u7ba1\u7406\u5668\u6765\u5b89\u88c5Python3\u3002<\/p>\n<\/p>\n<p><h3>2. \u4f7f\u7528\u5305\u7ba1\u7406\u5668\u5b89\u88c5Python3<\/h3>\n<\/p>\n<p><p>\u4e0d\u540c\u7684Linux\u53d1\u884c\u7248\u4f7f\u7528\u4e0d\u540c\u7684\u5305\u7ba1\u7406\u5668\u3002\u4f8b\u5982\uff0cUbuntu\u548cDebian\u4f7f\u7528<code>apt-get<\/code>\uff0c\u800cCentOS\u548cFedora\u4f7f\u7528<code>yum<\/code>\u3002<\/p>\n<\/p>\n<p><h4>\u5728Ubuntu\/Debian\u4e0a\u5b89\u88c5Python3<\/h4>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo apt-get update<\/p>\n<p>sudo apt-get install python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u5728CentOS\/Fedora\u4e0a\u5b89\u88c5Python3<\/h4>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo yum update<\/p>\n<p>sudo yum install python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e8c\u3001\u6253\u5f00Python3\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668<\/h2>\n<\/p>\n<p><h3>1. \u4f7f\u7528\u547d\u4ee4\u884c\u76f4\u63a5\u6253\u5f00<\/h3>\n<\/p>\n<p><p>\u5728\u547d\u4ee4\u884c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u53ef\u4ee5\u76f4\u63a5\u8fdb\u5165Python3\u7684\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2. \u4f7f\u7528Python3\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u4f60\u4e5f\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2aPython\u811a\u672c\u6587\u4ef6\uff0c\u7136\u540e\u4f7f\u7528Python3\u6765\u8fd0\u884c\u5b83\u3002\u9996\u5148\uff0c\u4f7f\u7528<code>nano<\/code>\u547d\u4ee4\u6765\u521b\u5efa\u548c\u7f16\u8f91Python\u811a\u672c\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">nano myscript.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u6587\u4ef6\u4e2d\u8f93\u5165\u4ee5\u4e0b\u793a\u4f8b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">print(&quot;Hello, World!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4fdd\u5b58\u5e76\u9000\u51fanano\u7f16\u8f91\u5668\uff0c\u7136\u540e\u5728\u547d\u4ee4\u884c\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u6267\u884c\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 myscript.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e09\u3001\u4f7f\u7528nano\u7f16\u8f91Python\u6587\u4ef6<\/h2>\n<\/p>\n<p><h3>1. \u521b\u5efa\u548c\u7f16\u8f91Python\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528<code>nano<\/code>\u547d\u4ee4\u521b\u5efa\u4e00\u4e2a\u65b0\u7684Python\u6587\u4ef6\u6216\u7f16\u8f91\u73b0\u6709\u7684Python\u6587\u4ef6\u3002\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>example.py<\/code>\u7684\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">nano example.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u6587\u4ef6\u4e2d\u8f93\u5165\u4f60\u7684Python\u4ee3\u7801\uff0c\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def greet(name):<\/p>\n<p>    return f&quot;Hello, {name}!&quot;<\/p>\n<p>print(greet(&quot;World&quot;))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2. \u4fdd\u5b58\u548c\u9000\u51fanano\u7f16\u8f91\u5668<\/h3>\n<\/p>\n<p><p>\u5728nano\u7f16\u8f91\u5668\u4e2d\uff0c\u6309<code>Ctrl + O<\/code>\u4fdd\u5b58\u6587\u4ef6\uff0c\u7136\u540e\u6309<code>Enter<\/code>\u786e\u8ba4\u3002\u63a5\u4e0b\u6765\uff0c\u6309<code>Ctrl + X<\/code>\u9000\u51fa\u7f16\u8f91\u5668\u3002<\/p>\n<\/p>\n<p><h3>3. \u8fd0\u884cPython\u6587\u4ef6<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u8fd0\u884c\u521a\u624d\u7f16\u8f91\u7684Python\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 example.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u56db\u3001\u5b89\u88c5\u548c\u4f7f\u7528Python\u6a21\u5757<\/h2>\n<\/p>\n<p><h3>1. \u4f7f\u7528<code>pip<\/code>\u5b89\u88c5\u6a21\u5757<\/h3>\n<\/p>\n<p><p>Python\u6709\u4e00\u4e2a\u5f3a\u5927\u7684\u5305\u7ba1\u7406\u5de5\u5177<code>pip<\/code>\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u5b89\u88c5\u5404\u79cdPython\u6a21\u5757\u3002\u4f8b\u5982\uff0c\u5b89\u88c5<code>requests<\/code>\u6a21\u5757\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip3 install requests<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2. \u4f7f\u7528\u5b89\u88c5\u7684\u6a21\u5757<\/h3>\n<\/p>\n<p><p>\u5728nano\u7f16\u8f91\u5668\u4e2d\u521b\u5efa\u6216\u7f16\u8f91\u4e00\u4e2aPython\u6587\u4ef6\uff0c\u5e76\u5bfc\u5165\u4f60\u5b89\u88c5\u7684\u6a21\u5757\u3002\u4f8b\u5982\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">nano request_example.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u6587\u4ef6\u4e2d\u8f93\u5165\u4ee5\u4e0b\u4ee3\u7801\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import requests<\/p>\n<p>response = requests.get(&#39;https:\/\/www.example.com&#39;)<\/p>\n<p>print(response.text)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4fdd\u5b58\u5e76\u9000\u51fanano\u7f16\u8f91\u5668\uff0c\u7136\u540e\u8fd0\u884c\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 request_example.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e94\u3001\u8c03\u8bd5\u548c\u6392\u9519<\/h2>\n<\/p>\n<p><h3>1. \u5e38\u89c1\u9519\u8bef\u53ca\u89e3\u51b3\u529e\u6cd5<\/h3>\n<\/p>\n<p><p>\u5728\u4f7f\u7528Python3\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u5e38\u89c1\u9519\u8bef\uff0c\u4f8b\u5982\u8bed\u6cd5\u9519\u8bef\u3001\u6a21\u5757\u672a\u627e\u5230\u9519\u8bef\u7b49\u3002\u4f60\u53ef\u4ee5\u901a\u8fc7\u9605\u8bfb\u9519\u8bef\u4fe1\u606f\u6765\u627e\u51fa\u95ee\u9898\u6240\u5728\uff0c\u5e76\u8fdb\u884c\u76f8\u5e94\u7684\u4fee\u6539\u3002<\/p>\n<\/p>\n<p><h3>2. \u4f7f\u7528\u8c03\u8bd5\u5de5\u5177<\/h3>\n<\/p>\n<p><p>Python\u63d0\u4f9b\u4e86\u591a\u79cd\u8c03\u8bd5\u5de5\u5177\uff0c\u4f8b\u5982<code>pdb<\/code>\u3002\u4f60\u53ef\u4ee5\u5728\u4ee3\u7801\u4e2d\u63d2\u5165\u8c03\u8bd5\u70b9\uff0c\u5e76\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u542f\u52a8\u8c03\u8bd5\u5668\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pdb; pdb.set_trace()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u8fd0\u884c\u811a\u672c\uff0c\u8c03\u8bd5\u5668\u4f1a\u5728\u8bbe\u7f6e\u7684\u65ad\u70b9\u5904\u6682\u505c\uff0c\u5141\u8bb8\u4f60\u68c0\u67e5\u53d8\u91cf\u3001\u6267\u884c\u4ee3\u7801\u7b49\u3002<\/p>\n<\/p>\n<p><h2>\u516d\u3001\u4f18\u5316\u548c\u63d0\u5347\u6027\u80fd<\/h2>\n<\/p>\n<p><h3>1. \u4f7f\u7528\u865a\u62df\u73af\u5883<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u53d1Python\u9879\u76ee\u65f6\uff0c\u5efa\u8bae\u4f7f\u7528\u865a\u62df\u73af\u5883\u6765\u9694\u79bb\u9879\u76ee\u7684\u4f9d\u8d56\u5173\u7cfb\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528<code>venv<\/code>\u6a21\u5757\u6765\u521b\u5efa\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 -m venv myenv<\/p>\n<p>source myenv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u865a\u62df\u73af\u5883\u4e2d\uff0c\u4f60\u53ef\u4ee5\u5b89\u88c5\u548c\u7ba1\u7406\u9879\u76ee\u7684\u4f9d\u8d56\uff0c\u800c\u4e0d\u5f71\u54cd\u7cfb\u7edf\u7684\u5168\u5c40Python\u73af\u5883\u3002<\/p>\n<\/p>\n<p><h3>2. \u4f7f\u7528\u9ad8\u6548\u7684\u6570\u636e\u7ed3\u6784\u548c\u7b97\u6cd5<\/h3>\n<\/p>\n<p><p>\u5728\u7f16\u5199Python\u4ee3\u7801\u65f6\uff0c\u9009\u62e9\u9ad8\u6548\u7684\u6570\u636e\u7ed3\u6784\u548c\u7b97\u6cd5\u53ef\u4ee5\u663e\u8457\u63d0\u5347\u6027\u80fd\u3002\u4f8b\u5982\uff0c\u4f7f\u7528\u5217\u8868\u63a8\u5bfc\u5f0f\u66ff\u4ee3\u5faa\u73af\u6765\u521b\u5efa\u5217\u8868\uff0c\u4f7f\u7528\u751f\u6210\u5668\u66ff\u4ee3\u5217\u8868\u6765\u5904\u7406\u5927\u6570\u636e\u96c6\u7b49\u3002<\/p>\n<\/p>\n<p><h2>\u4e03\u3001\u603b\u7ed3<\/h2>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0a\u8ff0\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u5728nano\u677f\u4e0a\u6210\u529f\u6253\u5f00\u5e76\u4f7f\u7528Python3\u8fdb\u884c\u5404\u79cd\u64cd\u4f5c\u3002\u4ece\u5b89\u88c5Python3\u3001\u7f16\u8f91\u548c\u8fd0\u884cPython\u811a\u672c\uff0c\u5230\u5b89\u88c5\u548c\u4f7f\u7528Python\u6a21\u5757\uff0c\u518d\u5230\u8c03\u8bd5\u548c\u4f18\u5316\u4ee3\u7801\uff0c\u6bcf\u4e00\u4e2a\u6b65\u9aa4\u90fd\u81f3\u5173\u91cd\u8981\u3002\u5e0c\u671b\u8fd9\u4e9b\u5185\u5bb9\u80fd\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u638c\u63e1\u5728nano\u677f\u4e0a\u4f7f\u7528Python3\u7684\u6280\u5de7\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728nano\u677f\u4e0a\u5b89\u88c5Python3\uff1f<\/strong><br \/>\u5728nano\u677f\u4e0a\u5b89\u88c5Python3\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7\u5305\u7ba1\u7406\u5668\u8fdb\u884c\u3002\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<code>sudo apt-get update<\/code>\u66f4\u65b0\u8f6f\u4ef6\u5305\u5217\u8868\uff0c\u7136\u540e\u4f7f\u7528<code>sudo apt-get install python3<\/code>\u5b89\u88c5Python3\u3002\u786e\u4fdd\u4f60\u7684nano\u677f\u8fde\u63a5\u5230\u4e92\u8054\u7f51\uff0c\u4ee5\u4fbf\u80fd\u591f\u4e0b\u8f7d\u6240\u9700\u7684\u6587\u4ef6\u3002<\/p>\n<p><strong>\u5728nano\u677f\u4e0a\u5982\u4f55\u4f7f\u7528Python3\u7f16\u5199\u548c\u8fd0\u884c\u811a\u672c\uff1f<\/strong><br \/>\u4f7f\u7528Python3\u7f16\u5199\u811a\u672c\u975e\u5e38\u7b80\u5355\u3002\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u8fdb\u5165Python\u4ea4\u4e92\u5f0f\u73af\u5883\uff0c\u8f93\u5165<code>python3<\/code>\u547d\u4ee4\uff0c\u6216\u8005\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\uff08\u5982nano\u6216vim\uff09\u521b\u5efa\u4e00\u4e2a\u4ee5<code>.py<\/code>\u7ed3\u5c3e\u7684\u6587\u4ef6\u3002\u5728\u6587\u4ef6\u4e2d\u7f16\u5199Python\u4ee3\u7801\u540e\uff0c\u4f7f\u7528\u547d\u4ee4<code>python3 your_script.py<\/code>\u6765\u8fd0\u884c\u811a\u672c\u3002<\/p>\n<p><strong>nano\u677f\u652f\u6301\u54ea\u4e9bPython\u5e93\uff1f<\/strong><br \/>nano\u677f\u652f\u6301\u591a\u79cdPython\u5e93\uff0c\u53ef\u4ee5\u901a\u8fc7<code>pip<\/code>\u547d\u4ee4\u5b89\u88c5\u5b83\u4eec\u3002\u5e38\u89c1\u7684\u5e93\u5305\u62ecNumPy\u3001Pandas\u3001Matplotlib\u7b49\u3002\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<code>pip install library_name<\/code>\u6765\u5b89\u88c5\u6240\u9700\u7684\u5e93\u3002\u8981\u786e\u4fdd\u5b89\u88c5\u6210\u529f\uff0c\u5efa\u8bae\u5728\u5b89\u88c5\u540e\u901a\u8fc7Python\u4ee3\u7801\u5bfc\u5165\u5e93\u8fdb\u884c\u6d4b\u8bd5\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728nano\u677f\u4e0a\u6253\u5f00Python3\u7684\u65b9\u6cd5\u6709\uff1a\u5728\u547d\u4ee4\u884c\u8f93\u5165python3\u3001\u4f7f\u7528nano\u547d\u4ee4\u7f16\u8f91Python\u6587\u4ef6\u3001\u5b89 [&hellip;]","protected":false},"author":3,"featured_media":1123022,"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\/1123014"}],"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=1123014"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1123014\/revisions"}],"predecessor-version":[{"id":1123027,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1123014\/revisions\/1123027"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1123022"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1123014"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1123014"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1123014"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}