{"id":1096623,"date":"2025-01-08T15:03:08","date_gmt":"2025-01-08T07:03:08","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1096623.html"},"modified":"2025-01-08T15:03:10","modified_gmt":"2025-01-08T07:03:10","slug":"%e6%a0%91%e8%8e%93%e6%b4%bepython%e7%a8%8b%e5%ba%8f%e5%a6%82%e4%bd%95%e8%bf%90%e8%a1%8c%e7%a8%8b%e5%ba%8f-2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1096623.html","title":{"rendered":"\u6811\u8393\u6d3epython\u7a0b\u5e8f\u5982\u4f55\u8fd0\u884c\u7a0b\u5e8f"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24211750\/f27702da-8d54-4615-b0cf-8c7eff8a70a4.webp\" alt=\"\u6811\u8393\u6d3epython\u7a0b\u5e8f\u5982\u4f55\u8fd0\u884c\u7a0b\u5e8f\" \/><\/p>\n<p><p> <strong>\u6811\u8393\u6d3e\u4e0a\u7684Python\u7a0b\u5e8f\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u8fd0\u884c\uff1a\u4f7f\u7528\u7ec8\u7aef\u3001\u901a\u8fc7Python\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u3001\u901a\u8fc7\u811a\u672c\u6587\u4ef6\u7b49\u3002<\/strong> \u6700\u5e38\u89c1\u7684\u65b9\u6cd5\u5305\u62ec\uff1a<strong>\u4f7f\u7528\u547d\u4ee4\u884c\u8fd0\u884cPython\u811a\u672c\u3001\u901a\u8fc7Python IDE\u8fd0\u884c\u3001\u8bbe\u7f6e\u811a\u672c\u81ea\u52a8\u542f\u52a8<\/strong>\u3002\u4e0b\u9762\u6211\u4eec\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5176\u4e2d\u4e00\u79cd\u65b9\u6cd5\uff0c\u5373\u4f7f\u7528\u547d\u4ee4\u884c\u8fd0\u884cPython\u811a\u672c\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u547d\u4ee4\u884c\u8fd0\u884cPython\u811a\u672c\u662f\u4e00\u79cd\u9ad8\u6548\u4e14\u5e38\u7528\u7684\u65b9\u6cd5\u3002\u9996\u5148\uff0c\u4f60\u9700\u8981\u786e\u4fdd\u4f60\u7684\u6811\u8393\u6d3e\u4e0a\u5df2\u7ecf\u5b89\u88c5\u4e86Python\u73af\u5883\u3002\u6811\u8393\u6d3e\u7684Raspbian\u64cd\u4f5c\u7cfb\u7edf\u9ed8\u8ba4\u5305\u542bPython 3\uff0c\u4f46\u4f60\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u786e\u8ba4\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\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/p>\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><h3>\u4e00\u3001\u5b89\u88c5\u548c\u914d\u7f6ePython\u73af\u5883<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u68c0\u67e5Python\u5b89\u88c5<\/strong>\uff1a\u6811\u8393\u6d3e\u901a\u5e38\u9884\u88c5\u4e86Python\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u8f93\u5165<code>python3 --version<\/code>\u6765\u68c0\u67e5\u662f\u5426\u5df2\u5b89\u88c5Python 3\u3002\u5982\u679c\u6ca1\u6709\u5b89\u88c5\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528<code>sudo apt-get install python3<\/code>\u6765\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5pip<\/strong>\uff1apip\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4<code>sudo apt-get install python3-pip<\/code>\u6765\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5\u5fc5\u8981\u7684\u5e93<\/strong>\uff1a\u6839\u636e\u4f60\u7684\u7a0b\u5e8f\u9700\u6c42\uff0c\u53ef\u80fd\u9700\u8981\u5b89\u88c5\u4e00\u4e9b\u7b2c\u4e09\u65b9\u5e93\u3002\u53ef\u4ee5\u4f7f\u7528<code>pip3 install &lt;\u5e93\u540d&gt;<\/code>\u6765\u5b89\u88c5\u3002\u4f8b\u5982\uff0c\u5b89\u88c5<code>numpy<\/code>\u53ef\u4ee5\u4f7f\u7528<code>pip3 install numpy<\/code>\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><h3>\u4e8c\u3001\u7f16\u5199Python\u811a\u672c<\/h3>\n<\/p>\n<ol>\n<li><strong>\u521b\u5efaPython\u811a\u672c<\/strong>\uff1a\u4f60\u53ef\u4ee5\u4f7f\u7528\u4efb\u4f55\u6587\u672c\u7f16\u8f91\u5668\u6765\u7f16\u5199Python\u811a\u672c\u3002\u5728\u6811\u8393\u6d3e\u4e0a\uff0c<code>nano<\/code>\u662f\u4e00\u4e2a\u5e38\u7528\u7684\u6587\u672c\u7f16\u8f91\u5668\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\u521b\u5efa\u548c\u7f16\u8f91\u4e00\u4e2aPython\u6587\u4ef6\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">nano myscript.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u7f16\u5199\u4ee3\u7801<\/strong>\uff1a\u5728\u6587\u4ef6\u4e2d\u7f16\u5199\u4f60\u7684Python\u4ee3\u7801\uff0c\u4f8b\u5982\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-python\">print(&quot;Hello, World!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u4fdd\u5b58\u6587\u4ef6<\/strong>\uff1a\u5728<code>nano<\/code>\u4e2d\uff0c\u6309<code>Ctrl+O<\/code>\u4fdd\u5b58\u6587\u4ef6\uff0c\u7136\u540e\u6309<code>Ctrl+X<\/code>\u9000\u51fa\u7f16\u8f91\u5668\u3002<\/li>\n<\/ol>\n<p><h3>\u4e09\u3001\u8fd0\u884cPython\u811a\u672c<\/h3>\n<\/p>\n<ol>\n<li><strong>\u4f7f\u7528\u547d\u4ee4\u884c\u8fd0\u884c\u811a\u672c<\/strong>\uff1a\u5728\u7ec8\u7aef\u4e2d\uff0c\u5bfc\u822a\u5230\u4f60\u7684Python\u811a\u672c\u6240\u5728\u7684\u76ee\u5f55\uff0c\u7136\u540e\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fd0\u884c\u811a\u672c\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">python3 myscript.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u67e5\u770b\u8f93\u51fa<\/strong>\uff1a\u4f60\u5e94\u8be5\u4f1a\u5728\u7ec8\u7aef\u4e2d\u770b\u5230\u4f60\u7684Python\u811a\u672c\u8f93\u51fa\u7684\u7ed3\u679c\u3002<\/li>\n<\/ol>\n<p><h3>\u56db\u3001\u4f7f\u7528Python IDE<\/h3>\n<\/p>\n<ol>\n<li><strong>\u5b89\u88c5Python IDE<\/strong>\uff1a\u4f60\u53ef\u4ee5\u5728\u6811\u8393\u6d3e\u4e0a\u5b89\u88c5\u4e00\u4e9b\u5e38\u7528\u7684Python\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\uff0c\u5982Thonny\u3001PyCharm\u7b49\u3002Thonny\u662f\u4e00\u4e2a\u8f7b\u91cf\u7ea7\u7684IDE\uff0c\u9002\u5408\u521d\u5b66\u8005\u4f7f\u7528\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">sudo apt-get install thonny<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u4f7f\u7528IDE\u7f16\u5199\u548c\u8fd0\u884c\u4ee3\u7801<\/strong>\uff1a\u6253\u5f00Thonny\uff0c\u5728\u7f16\u8f91\u5668\u4e2d\u7f16\u5199\u4f60\u7684Python\u4ee3\u7801\uff0c\u7136\u540e\u76f4\u63a5\u5728IDE\u4e2d\u8fd0\u884c\u4ee3\u7801\u3002<\/li>\n<\/ol>\n<p><h3>\u4e94\u3001\u8bbe\u7f6e\u811a\u672c\u81ea\u52a8\u542f\u52a8<\/h3>\n<\/p>\n<ol>\n<li><strong>\u7f16\u8f91rc.local<\/strong>\uff1a\u4f60\u53ef\u4ee5\u901a\u8fc7\u7f16\u8f91<code>\/etc\/rc.local<\/code>\u6587\u4ef6\u6765\u8bbe\u7f6e\u811a\u672c\u5728\u542f\u52a8\u65f6\u81ea\u52a8\u8fd0\u884c\u3002\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">sudo nano \/etc\/rc.local<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"2\">\n<li><strong>\u6dfb\u52a0\u542f\u52a8\u547d\u4ee4<\/strong>\uff1a\u5728<code>exit 0<\/code>\u884c\u4e4b\u524d\u6dfb\u52a0\u4f60\u7684Python\u811a\u672c\u542f\u52a8\u547d\u4ee4\uff0c\u4f8b\u5982\uff1a<\/li>\n<\/ol>\n<p><pre><code class=\"language-bash\">python3 \/home\/pi\/myscript.py &amp;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<ol start=\"3\">\n<li><strong>\u4fdd\u5b58\u6587\u4ef6\u5e76\u9000\u51fa<\/strong>\uff1a\u6309<code>Ctrl+O<\/code>\u4fdd\u5b58\u6587\u4ef6\uff0c\u7136\u540e\u6309<code>Ctrl+X<\/code>\u9000\u51fa\u7f16\u8f91\u5668\u3002<\/li>\n<\/ol>\n<p><h3>\u516d\u3001\u8c03\u8bd5\u548c\u4f18\u5316<\/h3>\n<\/p>\n<ol>\n<li>\n<p><strong>\u8c03\u8bd5\u4ee3\u7801<\/strong>\uff1a\u5982\u679c\u4f60\u7684\u811a\u672c\u6709\u95ee\u9898\uff0c\u53ef\u4ee5\u4f7f\u7528Python\u7684\u8c03\u8bd5\u5de5\u5177\uff0c\u5982<code>pdb<\/code>\uff0c\u6216\u8005\u5728IDE\u4e2d\u4f7f\u7528\u65ad\u70b9\u8c03\u8bd5\u529f\u80fd\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f18\u5316\u4ee3\u7801<\/strong>\uff1a\u6839\u636e\u9700\u8981\u4f18\u5316\u4f60\u7684\u4ee3\u7801\uff0c\u63d0\u9ad8\u8fd0\u884c\u6548\u7387\uff0c\u51cf\u5c11\u8d44\u6e90\u6d88\u8017\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u5728\u6811\u8393\u6d3e\u4e0a\u7f16\u5199\u3001\u8fd0\u884c\u548c\u8c03\u8bd5Python\u7a0b\u5e8f\u3002\u65e0\u8bba\u662f\u7b80\u5355\u7684\u811a\u672c\u8fd8\u662f\u590d\u6742\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u6811\u8393\u6d3e\u90fd\u80fd\u591f\u63d0\u4f9b\u4e00\u4e2a\u7075\u6d3b\u548c\u9ad8\u6548\u7684\u5f00\u53d1\u73af\u5883\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728\u6811\u8393\u6d3e\u4e0a\u5b89\u88c5Python\uff1f<\/strong><br \/>\u5728\u6811\u8393\u6d3e\u4e0a\uff0cPython\u901a\u5e38\u9884\u88c5\u5728\u64cd\u4f5c\u7cfb\u7edf\u4e2d\uff0c\u4f46\u60a8\u53ef\u4ee5\u901a\u8fc7\u7ec8\u7aef\u4f7f\u7528\u547d\u4ee4<code>sudo apt-get install python3<\/code>\u6765\u786e\u4fdd\u5b89\u88c5\u4e86\u6700\u65b0\u7248\u672c\u3002\u4e3a\u4e86\u9a8c\u8bc1\u5b89\u88c5\uff0c\u60a8\u53ef\u4ee5\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>python3 --version<\/code>\uff0c\u8fd9\u5c06\u663e\u793a\u5f53\u524d\u5b89\u88c5\u7684Python\u7248\u672c\u3002<\/p>\n<p><strong>\u5982\u4f55\u521b\u5efa\u548c\u8fd0\u884c\u4e00\u4e2a\u7b80\u5355\u7684Python\u7a0b\u5e8f\uff1f<\/strong><br \/>\u8981\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684Python\u7a0b\u5e8f\uff0c\u53ef\u4ee5\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\uff08\u5982nano\u6216vim\uff09\u6253\u5f00\u4e00\u4e2a\u65b0\u7684\u6587\u4ef6\u3002\u8f93\u5165\u60a8\u7684\u4ee3\u7801\uff0c\u4fdd\u5b58\u6587\u4ef6\u540e\uff0c\u4f7f\u7528\u547d\u4ee4<code>python3 \u6587\u4ef6\u540d.py<\/code>\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u8be5\u7a0b\u5e8f\u3002\u786e\u4fdd\u5728\u8fd0\u884c\u4e4b\u524d\uff0c\u60a8\u5df2\u7ecf\u5728\u6587\u4ef6\u4e2d\u5199\u5165\u6709\u6548\u7684Python\u4ee3\u7801\u3002<\/p>\n<p><strong>\u5982\u4f55\u5904\u7406\u6811\u8393\u6d3e\u4e0a\u7684Python\u5e93\u5b89\u88c5\uff1f<\/strong><br \/>\u5728\u6811\u8393\u6d3e\u4e0a\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7pip\u5de5\u5177\u8f7b\u677e\u5b89\u88c5Python\u5e93\u3002\u4f7f\u7528\u547d\u4ee4<code>pip3 install \u5e93\u540d<\/code>\u6765\u5b89\u88c5\u6240\u9700\u7684\u5e93\u3002\u5982\u679cpip\u6ca1\u6709\u5b89\u88c5\uff0c\u53ef\u4ee5\u901a\u8fc7<code>sudo apt-get install python3-pip<\/code>\u8fdb\u884c\u5b89\u88c5\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u60a8\u5c31\u53ef\u4ee5\u5728Python\u7a0b\u5e8f\u4e2d\u5bfc\u5165\u8fd9\u4e9b\u5e93\u5e76\u4f7f\u7528\u5b83\u4eec\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u6811\u8393\u6d3e\u4e0a\u7684Python\u7a0b\u5e8f\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u5f0f\u8fd0\u884c\uff1a\u4f7f\u7528\u7ec8\u7aef\u3001\u901a\u8fc7Python\u96c6\u6210\u5f00\u53d1\u73af\u5883\uff08IDE\uff09\u3001\u901a\u8fc7\u811a\u672c\u6587\u4ef6 [&hellip;]","protected":false},"author":3,"featured_media":1096628,"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\/1096623"}],"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=1096623"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1096623\/revisions"}],"predecessor-version":[{"id":1096630,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1096623\/revisions\/1096630"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1096628"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1096623"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1096623"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1096623"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}