{"id":923651,"date":"2024-12-26T14:53:17","date_gmt":"2024-12-26T06:53:17","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/923651.html"},"modified":"2024-12-26T14:53:19","modified_gmt":"2024-12-26T06:53:19","slug":"linux%e4%b8%8b%e5%a6%82%e4%bd%95%e7%94%a8python","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/923651.html","title":{"rendered":"linux\u4e0b\u5982\u4f55\u7528python"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24211617\/914c8d45-b250-4790-b28c-7d141c25267d.webp\" alt=\"linux\u4e0b\u5982\u4f55\u7528python\" \/><\/p>\n<p><p> \u5f00\u5934\u6bb5\u843d\uff1a<br \/>\u5728Linux\u4e0b\u4f7f\u7528Python\u8fdb\u884c\u7f16\u7a0b\u662f\u4e00\u9879\u975e\u5e38\u9ad8\u6548\u4e14\u53d7\u6b22\u8fce\u7684\u9009\u62e9\u3002<strong>\u5b89\u88c5Python\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u8fd0\u884cPython\u811a\u672c\u3001\u5229\u7528Linux\u7684\u6587\u672c\u7f16\u8f91\u5668\u7f16\u5199\u4ee3\u7801\u3001\u7ba1\u7406Python\u5305\u548c\u4f9d\u8d56\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883\u8fdb\u884c\u9879\u76ee\u9694\u79bb<\/strong>\u662fLinux\u7528\u6237\u5728\u4f7f\u7528Python\u65f6\u9700\u8981\u638c\u63e1\u7684\u51e0\u4e2a\u5173\u952e\u70b9\u3002\u8fd9\u91cc\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u5982\u4f55\u5728Linux\u73af\u5883\u4e0b\u5b89\u88c5\u548c\u914d\u7f6ePython\u3001\u5982\u4f55\u9ad8\u6548\u5730\u7f16\u5199\u548c\u8fd0\u884cPython\u4ee3\u7801\uff0c\u4ee5\u53ca\u5982\u4f55\u7ba1\u7406\u9879\u76ee\u7684\u4f9d\u8d56\u5173\u7cfb\u3002\u5c24\u5176\u662f\u4f7f\u7528\u865a\u62df\u73af\u5883\u8fdb\u884c\u9879\u76ee\u9694\u79bb\uff0c\u5b83\u53ef\u4ee5\u907f\u514d\u4e0d\u540c\u9879\u76ee\u95f4\u7684\u5305\u51b2\u7a81\uff0c\u662fPython\u5f00\u53d1\u4e2d\u4e00\u9879\u91cd\u8981\u7684\u6280\u5de7\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u5b89\u88c5Python<\/p>\n<\/p>\n<p><p>\u5728Linux\u7cfb\u7edf\u4e2d\uff0cPython\u901a\u5e38\u5df2\u7ecf\u9884\u88c5\u5728\u5927\u591a\u6570\u7684\u53d1\u884c\u7248\u4e2d\u3002\u7136\u800c\uff0c\u67d0\u4e9b\u60c5\u51b5\u4e0b\u53ef\u80fd\u9700\u8981\u5b89\u88c5\u7279\u5b9a\u7248\u672c\u7684Python\u6216\u8005\u66f4\u65b0\u5230\u6700\u65b0\u7248\u672c\u3002\u53ef\u4ee5\u901a\u8fc7\u5305\u7ba1\u7406\u5668\u5982<code>apt<\/code>\u3001<code>yum<\/code>\u3001<code>dnf<\/code>\u7b49\u6765\u5b89\u88c5\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u901a\u8fc7\u5305\u7ba1\u7406\u5668\u5b89\u88c5<\/strong><\/p>\n<\/p>\n<p><p>\u5bf9\u4e8eDebian\/Ubuntu\u7cfb\u7edf\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Python\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo apt update<\/p>\n<p>sudo apt install python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5bf9\u4e8eRed Hat\/CentOS\u7cfb\u7edf\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">sudo yum install python3<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7<code>python3 --version<\/code>\u547d\u4ee4\u6765\u786e\u8ba4\u5b89\u88c5\u662f\u5426\u6210\u529f\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u5b89\u88c5\u6307\u5b9a\u7248\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u6709\u65f6\u9700\u8981\u5b89\u88c5\u7279\u5b9a\u7248\u672c\u7684Python\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pyenv<\/code>\u5de5\u5177\uff0c\u8fd9\u4e2a\u5de5\u5177\u5141\u8bb8\u7528\u6237\u5728\u540c\u4e00\u7cfb\u7edf\u4e0a\u5b89\u88c5\u548c\u7ba1\u7406\u591a\u4e2aPython\u7248\u672c\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">curl https:\/\/pyenv.run | bash<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\u5b89\u88c5\u6307\u5b9a\u7248\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pyenv install 3.x.x<\/p>\n<p>pyenv global 3.x.x<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u8fd0\u884cPython\u811a\u672c<\/p>\n<\/p>\n<p><p>\u547d\u4ee4\u884c\u662fLinux\u4e2d\u975e\u5e38\u5f3a\u5927\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u76f4\u63a5\u7528\u6765\u8fd0\u884cPython\u811a\u672c\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u8fd0\u884cPython\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u7ec8\u7aef\u8f93\u5165<code>python3<\/code>\u5373\u53ef\u8fdb\u5165Python\u4ea4\u4e92\u5f0f\u89e3\u91ca\u5668\uff0c\u5728\u8fd9\u91cc\u53ef\u4ee5\u76f4\u63a5\u8f93\u5165Python\u4ee3\u7801\u8fdb\u884c\u6d4b\u8bd5\u548c\u8fd0\u884c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u8fd0\u884cPython\u811a\u672c\u6587\u4ef6<\/strong><\/p>\n<\/p>\n<p><p>\u5047\u8bbe\u6709\u4e00\u4e2a\u540d\u4e3a<code>script.py<\/code>\u7684Python\u811a\u672c\u6587\u4ef6\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u8fd0\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u6267\u884c\u811a\u672c\u4e2d\u7684\u6240\u6709\u4ee3\u7801\uff0c\u5e76\u5728\u7ec8\u7aef\u4e2d\u8f93\u51fa\u7ed3\u679c\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u5229\u7528Linux\u7684\u6587\u672c\u7f16\u8f91\u5668\u7f16\u5199\u4ee3\u7801<\/p>\n<\/p>\n<p><p>Linux\u63d0\u4f9b\u4e86\u591a\u79cd\u6587\u672c\u7f16\u8f91\u5668\u7528\u4e8e\u7f16\u5199Python\u4ee3\u7801\uff0c\u5982<code>vim<\/code>\u3001<code>nano<\/code>\u3001<code>emacs<\/code>\u7b49\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528vim\u7f16\u8f91\u5668<\/strong><\/p>\n<\/p>\n<p><p>vim\u662f\u4e00\u4e2a\u5f3a\u5927\u7684\u6587\u672c\u7f16\u8f91\u5668\uff0c\u652f\u6301\u8bed\u6cd5\u9ad8\u4eae\u548c\u591a\u79cd\u63d2\u4ef6\uff0c\u975e\u5e38\u9002\u5408\u7f16\u5199Python\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">vim script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fdb\u5165vim\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7<code>i<\/code>\u952e\u8fdb\u5165\u63d2\u5165\u6a21\u5f0f\uff0c\u5f00\u59cb\u7f16\u5199\u4ee3\u7801\u3002\u5b8c\u6210\u540e\u6309<code>Esc<\/code>\u9000\u51fa\u63d2\u5165\u6a21\u5f0f\uff0c\u8f93\u5165<code>:wq<\/code>\u4fdd\u5b58\u5e76\u9000\u51fa\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528nano\u7f16\u8f91\u5668<\/strong><\/p>\n<\/p>\n<p><p>nano\u662f\u4e00\u4e2a\u7b80\u5355\u6613\u7528\u7684\u6587\u672c\u7f16\u8f91\u5668\uff0c\u9002\u5408\u521d\u5b66\u8005\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">nano script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u76f4\u63a5\u5f00\u59cb\u7f16\u5199\u4ee3\u7801\uff0c\u5b8c\u6210\u540e\u6309<code>Ctrl + X<\/code>\uff0c\u7136\u540e\u6309<code>Y<\/code>\u4fdd\u5b58\u5e76\u9000\u51fa\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u7ba1\u7406Python\u5305\u548c\u4f9d\u8d56<\/p>\n<\/p>\n<p><p>Python\u62e5\u6709\u4e30\u5bcc\u7684\u7b2c\u4e09\u65b9\u5e93\u548c\u6a21\u5757\uff0c\u4f7f\u7528\u8fd9\u4e9b\u5e93\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528pip\u5b89\u88c5\u5305<\/strong><\/p>\n<\/p>\n<p><p><code>pip<\/code>\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u7528\u4e8e\u5b89\u88c5\u548c\u7ba1\u7406Python\u5305\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install package_name<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528<code>pip list<\/code>\u547d\u4ee4\u67e5\u770b\u5df2\u5b89\u88c5\u7684\u5305\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7ba1\u7406\u9879\u76ee\u4f9d\u8d56<\/strong><\/p>\n<\/p>\n<p><p>\u901a\u5e38\u5728\u9879\u76ee\u6839\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a<code>requirements.txt<\/code>\u6587\u4ef6\uff0c\u8bb0\u5f55\u9879\u76ee\u6240\u9700\u7684\u6240\u6709\u5305\u53ca\u5176\u7248\u672c\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5\u8fd9\u4e9b\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install -r requirements.txt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u4f7f\u7528\u865a\u62df\u73af\u5883\u8fdb\u884c\u9879\u76ee\u9694\u79bb<\/p>\n<\/p>\n<p><p>\u865a\u62df\u73af\u5883\u5141\u8bb8\u4e3a\u6bcf\u4e2a\u9879\u76ee\u521b\u5efa\u72ec\u7acb\u7684Python\u73af\u5883\uff0c\u907f\u514d\u5305\u51b2\u7a81\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u521b\u5efa\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528<code>venv<\/code>\u6a21\u5757\u53ef\u4ee5\u521b\u5efa\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python3 -m venv myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u5728\u5f53\u524d\u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>myenv<\/code>\u7684\u865a\u62df\u73af\u5883\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6fc0\u6d3b\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\u540e\uff0c\u6240\u6709\u7684<code>pip<\/code>\u64cd\u4f5c\u90fd\u4f1a\u5728\u8be5\u73af\u5883\u4e2d\u6267\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">source myenv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6fc0\u6d3b\u540e\uff0c\u7ec8\u7aef\u63d0\u793a\u7b26\u524d\u4f1a\u663e\u793a\u865a\u62df\u73af\u5883\u7684\u540d\u79f0\uff0c\u8868\u793a\u5f53\u524d\u5904\u4e8e\u8be5\u865a\u62df\u73af\u5883\u4e2d\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u9000\u51fa\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u5b8c\u6210\u5de5\u4f5c\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u9000\u51fa\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">deactivate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u516d\u3001\u8c03\u8bd5Python\u4ee3\u7801<\/p>\n<\/p>\n<p><p>\u8c03\u8bd5\u662f\u5f00\u53d1\u8fc7\u7a0b\u4e2d\u5fc5\u4e0d\u53ef\u5c11\u7684\u4e00\u90e8\u5206\u3002Python\u63d0\u4f9b\u4e86\u591a\u79cd\u8c03\u8bd5\u5de5\u5177\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528print\u8bed\u53e5<\/strong><\/p>\n<\/p>\n<p><p>\u5728\u4ee3\u7801\u4e2d\u63d2\u5165<code>print<\/code>\u8bed\u53e5\u53ef\u4ee5\u5feb\u901f\u67e5\u770b\u53d8\u91cf\u7684\u503c\u548c\u7a0b\u5e8f\u7684\u6267\u884c\u6d41\u7a0b\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528pdb\u6a21\u5757<\/strong><\/p>\n<\/p>\n<p><p><code>pdb<\/code>\u662fPython\u81ea\u5e26\u7684\u8c03\u8bd5\u5668\uff0c\u53ef\u4ee5\u5728\u4ee3\u7801\u4e2d\u8bbe\u7f6e\u65ad\u70b9\uff0c\u9010\u6b65\u6267\u884c\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><p>\u5728\u811a\u672c\u4e2d\u63d2\u5165\u4ee5\u4e0b\u4ee3\u7801\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>\u8fd0\u884c\u811a\u672c\u65f6\u4f1a\u5728\u8fd9\u91cc\u6682\u505c\uff0c\u53ef\u4ee5\u8f93\u5165\u8c03\u8bd5\u547d\u4ee4\u8fdb\u884c\u8c03\u8bd5\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e03\u3001\u81ea\u52a8\u5316\u4efb\u52a1\u548c\u811a\u672c<\/p>\n<\/p>\n<p><p>Python\u4e0eLinux\u7ed3\u5408\u53ef\u4ee5\u5b9e\u73b0\u8bb8\u591a\u81ea\u52a8\u5316\u4efb\u52a1\u548c\u811a\u672c\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u7f16\u5199\u81ea\u52a8\u5316\u811a\u672c<\/strong><\/p>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528Python\u7f16\u5199\u811a\u672c\uff0c\u5b9e\u73b0\u6587\u4ef6\u7ba1\u7406\u3001\u6570\u636e\u5904\u7406\u7b49\u81ea\u52a8\u5316\u4efb\u52a1\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528cron\u5b9a\u65f6\u4efb\u52a1<\/strong><\/p>\n<\/p>\n<p><p>Linux\u7684<code>cron<\/code>\u670d\u52a1\u53ef\u4ee5\u5b9a\u65f6\u6267\u884cPython\u811a\u672c\uff0c\u5b9e\u73b0\u5b9a\u65f6\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><p>\u7f16\u8f91<code>crontab<\/code>\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">crontab -e<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6dfb\u52a0\u4e00\u6761\u5b9a\u65f6\u4efb\u52a1\uff0c\u4f8b\u5982\u6bcf\u5929\u51cc\u6668\u8fd0\u884c\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">0 0 * * * \/usr\/bin\/python3 \/path\/to\/script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u516b\u3001Python\u4e0eLinux\u547d\u4ee4\u884c\u5de5\u5177\u7ed3\u5408<\/p>\n<\/p>\n<p><p>Python\u53ef\u4ee5\u4e0eLinux\u547d\u4ee4\u884c\u5de5\u5177\u7ed3\u5408\u4f7f\u7528\uff0c\u63d0\u9ad8\u5de5\u4f5c\u6548\u7387\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528subprocess\u6a21\u5757<\/strong><\/p>\n<\/p>\n<p><p><code>subprocess<\/code>\u6a21\u5757\u53ef\u4ee5\u5728Python\u4e2d\u8c03\u7528Linux\u547d\u4ee4\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import subprocess<\/p>\n<p>result = subprocess.run([&#39;ls&#39;, &#39;-l&#39;], capture_output=True, text=True)<\/p>\n<p>print(result.stdout)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528os\u6a21\u5757<\/strong><\/p>\n<\/p>\n<p><p><code>os<\/code>\u6a21\u5757\u53ef\u4ee5\u7528\u4e8e\u6587\u4ef6\u64cd\u4f5c\u3001\u73af\u5883\u53d8\u91cf\u8bbf\u95ee\u7b49\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import os<\/p>\n<p>files = os.listdir(&#39;.&#39;)<\/p>\n<p>for file in files:<\/p>\n<p>    print(file)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e5d\u3001\u5b66\u4e60\u548c\u793e\u533a\u8d44\u6e90<\/p>\n<\/p>\n<p><p>\u5728Linux\u4e0b\u4f7f\u7528Python\u7684\u8fc7\u7a0b\u4e2d\uff0c\u5b66\u4e60\u548c\u5bfb\u6c42\u5e2e\u52a9\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5728\u7ebf\u6559\u7a0b\u548c\u6587\u6863<\/strong><\/p>\n<\/p>\n<p><p>\u5b98\u65b9\u6587\u6863\u3001\u5728\u7ebf\u8bfe\u7a0b\u5982Codecademy\u3001Coursera\u7b49\u90fd\u662f\u5b66\u4e60Python\u7684\u597d\u8d44\u6e90\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u793e\u533a\u652f\u6301<\/strong><\/p>\n<\/p>\n<p><p>Python\u6709\u4e00\u4e2a\u6d3b\u8dc3\u7684\u793e\u533a\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bba\u575b\u3001\u90ae\u4ef6\u5217\u8868\u548c\u793e\u4ea4\u5a92\u4f53\u7b49\u6e20\u9053\u5bfb\u6c42\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u603b\u7ed3\uff1a\u5728Linux\u4e0b\u4f7f\u7528Python\uff0c\u7528\u6237\u9700\u8981\u638c\u63e1\u5b89\u88c5\u548c\u914d\u7f6e\u3001\u4ee3\u7801\u7f16\u5199\u3001\u8c03\u8bd5\u3001\u5305\u7ba1\u7406\u3001\u81ea\u52a8\u5316\u811a\u672c\u3001\u4e0e\u547d\u4ee4\u884c\u7ed3\u5408\u7b49\u591a\u65b9\u9762\u7684\u6280\u80fd\u3002\u901a\u8fc7\u4e0d\u65ad\u5b9e\u8df5\u548c\u5b66\u4e60\uff0c\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u548c\u6280\u80fd\u6c34\u5e73\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Linux\u4e0a\u5b89\u88c5Python\uff1f<\/strong><br \/>\u5728Linux\u4e0a\u5b89\u88c5Python\u901a\u5e38\u53ef\u4ee5\u901a\u8fc7\u5305\u7ba1\u7406\u5668\u6765\u5b8c\u6210\u3002\u5927\u591a\u6570Linux\u53d1\u884c\u7248\u5df2\u7ecf\u9884\u88c5\u4e86Python\u3002\u53ef\u4ee5\u901a\u8fc7\u5728\u7ec8\u7aef\u4e2d\u8f93\u5165<code>python --version<\/code>\u6216<code>python3 --version<\/code>\u6765\u68c0\u67e5\u5f53\u524d\u5b89\u88c5\u7684\u7248\u672c\u3002\u5982\u679c\u9700\u8981\u5b89\u88c5\u6216\u66f4\u65b0Python\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u547d\u4ee4\uff1a  <\/p>\n<ul>\n<li>\u5bf9\u4e8eDebian\/Ubuntu\uff1a<code>sudo apt-get install python3<\/code>  <\/li>\n<li>\u5bf9\u4e8eFedora\uff1a<code>sudo dnf install python3<\/code>  <\/li>\n<li>\u5bf9\u4e8eArch Linux\uff1a<code>sudo pacman -S python<\/code><br \/>\u786e\u4fdd\u5728\u5b89\u88c5\u540e\u518d\u6b21\u68c0\u67e5\u7248\u672c\u4ee5\u786e\u8ba4\u5b89\u88c5\u6210\u529f\u3002<\/li>\n<\/ul>\n<p><strong>\u5982\u4f55\u5728Linux\u4e2d\u8fd0\u884cPython\u811a\u672c\uff1f<\/strong><br \/>\u8fd0\u884cPython\u811a\u672c\u975e\u5e38\u7b80\u5355\u3002\u9996\u5148\uff0c\u786e\u4fdd\u811a\u672c\u6587\u4ef6\u5177\u6709\u6267\u884c\u6743\u9650\u3002\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<code>chmod +x your_script.py<\/code>\u6765\u8d4b\u4e88\u6267\u884c\u6743\u9650\u3002\u7136\u540e\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u5728\u7ec8\u7aef\u8f93\u5165<code>.\/your_script.py<\/code>\u6765\u8fd0\u884c\u811a\u672c\u3002\u5982\u679c\u811a\u672c\u6ca1\u6709\u6267\u884c\u6743\u9650\uff0c\u4e5f\u53ef\u4ee5\u4f7f\u7528<code>python your_script.py<\/code>\u6216<code>python3 your_script.py<\/code>\u6765\u6267\u884c\u3002<\/p>\n<p><strong>\u5728Linux\u4e0a\u4f7f\u7528Python\u5f00\u53d1\u73af\u5883\u7684\u63a8\u8350\u5de5\u5177\u6709\u54ea\u4e9b\uff1f<\/strong><br \/>\u5728Linux\u4e0a\u8fdb\u884cPython\u5f00\u53d1\u65f6\uff0c\u4f7f\u7528\u5408\u9002\u7684\u5f00\u53d1\u5de5\u5177\u53ef\u4ee5\u63d0\u9ad8\u6548\u7387\u3002\u63a8\u8350\u7684\u5f00\u53d1\u73af\u5883\u5305\u62ec\uff1a  <\/p>\n<ul>\n<li><strong>PyCharm<\/strong>\uff1a\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684IDE\uff0c\u9002\u5408\u5927\u578b\u9879\u76ee\u5f00\u53d1\u3002  <\/li>\n<li><strong>Visual Studio Code<\/strong>\uff1a\u8f7b\u91cf\u7ea7\u7f16\u8f91\u5668\uff0c\u652f\u6301\u4e30\u5bcc\u7684\u6269\u5c55\uff0c\u53ef\u4ee5\u81ea\u5b9a\u4e49\u5f00\u53d1\u73af\u5883\u3002  <\/li>\n<li><strong>Jupyter Notebook<\/strong>\uff1a\u9002\u5408\u6570\u636e\u79d1\u5b66\u548c\u4ea4\u4e92\u5f0f\u7f16\u7a0b\uff0c\u65b9\u4fbf\u8fdb\u884c\u6570\u636e\u5206\u6790\u548c\u53ef\u89c6\u5316\u3002<br \/>\u9009\u62e9\u5408\u9002\u7684\u5de5\u5177\u53ef\u4ee5\u6839\u636e\u4e2a\u4eba\u7684\u9700\u6c42\u548c\u9879\u76ee\u7c7b\u578b\u6765\u51b3\u5b9a\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"\u5f00\u5934\u6bb5\u843d\uff1a\u5728Linux\u4e0b\u4f7f\u7528Python\u8fdb\u884c\u7f16\u7a0b\u662f\u4e00\u9879\u975e\u5e38\u9ad8\u6548\u4e14\u53d7\u6b22\u8fce\u7684\u9009\u62e9\u3002\u5b89\u88c5Python\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u8fd0\u884c [&hellip;]","protected":false},"author":3,"featured_media":923656,"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\/923651"}],"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=923651"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/923651\/revisions"}],"predecessor-version":[{"id":923658,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/923651\/revisions\/923658"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/923656"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=923651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=923651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=923651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}