{"id":925108,"date":"2024-12-26T15:25:13","date_gmt":"2024-12-26T07:25:13","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/925108.html"},"modified":"2024-12-26T15:25:15","modified_gmt":"2024-12-26T07:25:15","slug":"termux%e5%a6%82%e4%bd%95python","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/925108.html","title":{"rendered":"termux\u5982\u4f55python"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/24212433\/7f8dd5f7-ccbc-4207-8367-311fd7aee955.webp\" alt=\"termux\u5982\u4f55python\" \/><\/p>\n<p><p> <strong>\u5728Termux\u4e2d\u5b89\u88c5\u548c\u4f7f\u7528Python\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u5b89\u88c5Termux\u3001\u66f4\u65b0\u8f6f\u4ef6\u5305\u3001\u5b89\u88c5Python\u3001\u9a8c\u8bc1\u5b89\u88c5\u3001\u4f7f\u7528Python\u89e3\u91ca\u5668\u3001\u5b89\u88c5pip\u548cPython\u5e93\u3001\u7f16\u5199\u548c\u8fd0\u884cPython\u811a\u672c\u3002<\/strong>\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u8be6\u7ec6\u63cf\u8ff0\u8fd9\u4e9b\u6b65\u9aa4\u4e2d\u7684\u4e00\u9879\uff1a\u5b89\u88c5Python\u3002<\/p>\n<\/p>\n<p><p>\u5728Termux\u4e2d\uff0c\u5b89\u88c5Python\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u4f7f\u7528Termux\u7684\u5305\u7ba1\u7406\u5668apt\u3002\u9996\u5148\uff0c\u786e\u4fdd\u4f60\u7684\u8f6f\u4ef6\u5305\u5217\u8868\u662f\u6700\u65b0\u7684\uff0c\u8fd9\u6837\u53ef\u4ee5\u907f\u514d\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u51fa\u73b0\u4e0d\u5fc5\u8981\u7684\u95ee\u9898\u3002\u63a5\u7740\uff0c\u4f7f\u7528apt\u547d\u4ee4\u6765\u5b89\u88c5Python\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u4f1a\u81ea\u52a8\u5b89\u88c5Python\u7684\u6700\u65b0\u7248\u672c\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u547d\u4ee4\u884c\u8f93\u5165<code>python<\/code>\u6765\u542f\u52a8Python\u89e3\u91ca\u5668\uff0c\u4ece\u800c\u9a8c\u8bc1Python\u662f\u5426\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<hr>\n<p><p>\u4e00\u3001\u5b89\u88c5Termux<\/p>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4f7f\u7528Python\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u5728Android\u8bbe\u5907\u4e0a\u5b89\u88c5Termux\u3002Termux\u662f\u4e00\u4e2aAndroid\u7ec8\u7aef\u4eff\u771f\u5668\u53caLinux\u73af\u5883\u5e94\u7528\u7a0b\u5e8f\u3002\u53ef\u4ee5\u4eceGoogle Play\u5546\u5e97\u6216\u8005F-Droid\u4e0a\u4e0b\u8f7d\u3002\u5b89\u88c5\u540e\uff0c\u542f\u52a8Termux\u5e94\u7528\uff0c\u5c06\u770b\u5230\u4e00\u4e2a\u547d\u4ee4\u884c\u754c\u9762\u3002<\/p>\n<\/p>\n<p><p>\u4e8c\u3001\u66f4\u65b0\u8f6f\u4ef6\u5305<\/p>\n<\/p>\n<p><p>\u5728Termux\u4e2d\uff0c\u9996\u5148\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u66f4\u65b0\u8f6f\u4ef6\u5305\u548c\u5305\u5217\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pkg update<\/p>\n<p>pkg upgrade<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e9b\u547d\u4ee4\u5c06\u786e\u4fdd\u4f60\u7684Termux\u73af\u5883\u4e2d\u7684\u6240\u6709\u8f6f\u4ef6\u5305\u90fd\u662f\u6700\u65b0\u7684\uff0c\u5e76\u4fee\u590d\u4efb\u4f55\u5df2\u77e5\u7684\u5b89\u5168\u6f0f\u6d1e\u3002<\/p>\n<\/p>\n<p><p>\u4e09\u3001\u5b89\u88c5Python<\/p>\n<\/p>\n<p><p>\u8981\u5728Termux\u4e2d\u5b89\u88c5Python\uff0c\u53ea\u9700\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pkg install python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u547d\u4ee4\u5c06\u5b89\u88c5Python\u7684\u6700\u65b0\u7248\u672c\u3002\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0c\u53ef\u80fd\u9700\u8981\u786e\u8ba4\u5b89\u88c5\u8fc7\u7a0b\u4e2d\u7684\u4e00\u4e9b\u6b65\u9aa4\uff0c\u53ea\u9700\u8f93\u5165\u201cy\u201d\u5e76\u56de\u8f66\u5373\u53ef\u3002<\/p>\n<\/p>\n<p><p>\u56db\u3001\u9a8c\u8bc1Python\u5b89\u88c5<\/p>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u9a8c\u8bc1Python\u662f\u5426\u5df2\u6210\u529f\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u663e\u793aPython\u7684\u5f53\u524d\u7248\u672c\u4fe1\u606f\uff0c\u786e\u8ba4\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<p><p>\u4e94\u3001\u4f7f\u7528Python\u89e3\u91ca\u5668<\/p>\n<\/p>\n<p><p>\u5728Termux\u4e2d\uff0c\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u542f\u52a8Python\u89e3\u91ca\u5668\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fdb\u5165Python\u89e3\u91ca\u5668\u540e\uff0c\u4f60\u53ef\u4ee5\u8f93\u5165Python\u4ee3\u7801\u5e76\u7acb\u5373\u770b\u5230\u7ed3\u679c\u3002\u8981\u9000\u51fa\u89e3\u91ca\u5668\uff0c\u53ef\u4ee5\u4f7f\u7528<code>exit()<\/code>\u6216\u6309<code>Ctrl + D<\/code>\u3002<\/p>\n<\/p>\n<p><p>\u516d\u3001\u5b89\u88c5pip\u548cPython\u5e93<\/p>\n<\/p>\n<p><p>pip\u662fPython\u7684\u5305\u7ba1\u7406\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u6765\u5b89\u88c5\u548c\u7ba1\u7406Python\u8f6f\u4ef6\u5305\u3002\u5728Termux\u4e2d\uff0cpip\u901a\u5e38\u4e0ePython\u4e00\u8d77\u5b89\u88c5\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u786e\u8ba4pip\u662f\u5426\u5df2\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u672a\u5b89\u88c5\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5pip\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pkg install python-pip<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528pip\u6765\u5b89\u88c5Python\u5e93\u3002\u4f8b\u5982\uff0c\u8981\u5b89\u88c5requests\u5e93\uff0c\u53ef\u4ee5\u8fd0\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install requests<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4e03\u3001\u7f16\u5199\u548c\u8fd0\u884cPython\u811a\u672c<\/p>\n<\/p>\n<p><p>\u5728Termux\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5185\u7f6e\u7684\u6587\u672c\u7f16\u8f91\u5668\uff08\u5982nano\u6216vim\uff09\u7f16\u5199Python\u811a\u672c\u3002\u4f8b\u5982\uff0c\u4f7f\u7528nano\u521b\u5efa\u4e00\u4e2a\u540d\u4e3ahello.py\u7684Python\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">nano hello.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\">print(&quot;Hello, Termux!&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4fdd\u5b58\u5e76\u9000\u51fanano\uff0c\u7136\u540e\u8fd0\u884c\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">python hello.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u8f93\u51fa\u201cHello, Termux!\u201d\u3002<\/p>\n<\/p>\n<p><p>\u516b\u3001\u7ba1\u7406Python\u73af\u5883<\/p>\n<\/p>\n<p><p>\u5728\u5f00\u53d1\u66f4\u590d\u6742\u7684Python\u9879\u76ee\u65f6\uff0c\u53ef\u80fd\u9700\u8981\u7ba1\u7406\u591a\u4e2aPython\u73af\u5883\u3002\u53ef\u4ee5\u4f7f\u7528virtualenv\u5de5\u5177\u5728Termux\u4e2d\u521b\u5efa\u865a\u62df\u73af\u5883\uff0c\u9694\u79bb\u9879\u76ee\u4f9d\u8d56\u5173\u7cfb\u3002\u9996\u5148\u5b89\u88c5virtualenv\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install virtualenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u521b\u5efa\u5e76\u6fc0\u6d3b\u4e00\u4e2a\u65b0\u7684\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">virtualenv myenv<\/p>\n<p>source myenv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6fc0\u6d3b\u540e\uff0c\u6240\u6709\u901a\u8fc7pip\u5b89\u88c5\u7684\u5e93\u5c06\u53ea\u5728\u8be5\u73af\u5883\u4e2d\u53ef\u7528\u3002\u5b8c\u6210\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<p><p>\u4e5d\u3001\u89e3\u51b3\u5e38\u89c1\u95ee\u9898<\/p>\n<\/p>\n<p><p>\u5728\u4f7f\u7528Termux\u548cPython\u65f6\uff0c\u53ef\u80fd\u4f1a\u9047\u5230\u4e00\u4e9b\u5e38\u89c1\u95ee\u9898\u3002\u4f8b\u5982\uff0cPython\u8def\u5f84\u914d\u7f6e\u9519\u8bef\u3001\u5e93\u5b89\u88c5\u5931\u8d25\u7b49\u3002\u901a\u5e38\uff0c\u901a\u8fc7\u786e\u4fdd\u8f6f\u4ef6\u5305\u7684\u6700\u65b0\u7248\u672c\u548c\u6b63\u786e\u7684\u8def\u5f84\u914d\u7f6e\u53ef\u4ee5\u89e3\u51b3\u8fd9\u4e9b\u95ee\u9898\u3002\u6b64\u5916\uff0cTermux\u793e\u533a\u548c\u5728\u7ebf\u8bba\u575b\u4e5f\u662f\u89e3\u51b3\u95ee\u9898\u7684\u826f\u597d\u8d44\u6e90\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u5728Termux\u4e2d\u6210\u529f\u5b89\u88c5\u548c\u4f7f\u7528Python\u3002\u8fd9\u4e3aAndroid\u8bbe\u5907\u4e0a\u7684Python\u5f00\u53d1\u63d0\u4f9b\u4e86\u6781\u5927\u7684\u7075\u6d3b\u6027\u548c\u4fbf\u5229\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Termux\u4e2d\u5b89\u88c5Python\uff1f<\/strong><br \/>\u5728Termux\u4e2d\u5b89\u88c5Python\u975e\u5e38\u7b80\u5355\u3002\u60a8\u53ea\u9700\u6253\u5f00Termux\u7ec8\u7aef\u5e76\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<code>pkg install python<\/code>\u3002\u8fd9\u5c06\u81ea\u52a8\u4e0b\u8f7d\u5e76\u5b89\u88c5\u6700\u65b0\u7248\u672c\u7684Python\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u8f93\u5165<code>python<\/code>\u6216<code>python3<\/code>\u547d\u4ee4\u6765\u542f\u52a8Python\u89e3\u91ca\u5668\u3002<\/p>\n<p><strong>\u5728Termux\u4e2d\u5982\u4f55\u8fd0\u884cPython\u811a\u672c\uff1f<\/strong><br \/>\u8981\u5728Termux\u4e2d\u8fd0\u884cPython\u811a\u672c\uff0c\u60a8\u9700\u8981\u5148\u521b\u5efa\u4e00\u4e2aPython\u6587\u4ef6\u3002\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\uff08\u5982<code>nano<\/code>\u6216<code>vim<\/code>\uff09\u521b\u5efa\u4e00\u4e2a\u6587\u4ef6\uff0c\u4f8b\u5982<code>script.py<\/code>\u3002\u5728\u6587\u4ef6\u4e2d\u7f16\u5199\u60a8\u7684Python\u4ee3\u7801\u540e\uff0c\u4fdd\u5b58\u5e76\u9000\u51fa\u7f16\u8f91\u5668\u3002\u63a5\u7740\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<code>python script.py<\/code>\u6216<code>python3 script.py<\/code>\u6765\u6267\u884c\u8be5\u811a\u672c\u3002<\/p>\n<p><strong>Termux\u4e2dPython\u73af\u5883\u7684\u7ba1\u7406\u65b9\u6cd5\u662f\u4ec0\u4e48\uff1f<\/strong><br \/>\u5728Termux\u4e2d\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528<code>pip<\/code>\u6765\u5b89\u88c5\u548c\u7ba1\u7406Python\u5305\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cPython\u5b89\u88c5\u540e\u4f1a\u81ea\u52a8\u5305\u542b<code>pip<\/code>\u3002\u8981\u67e5\u770b\u5df2\u5b89\u88c5\u7684\u5305\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<code>pip list<\/code>\u3002\u5982\u679c\u9700\u8981\u5b89\u88c5\u65b0\u7684\u5305\uff0c\u53ea\u9700\u8fd0\u884c<code>pip install package_name<\/code>\uff0c\u5c06<code>package_name<\/code>\u66ff\u6362\u4e3a\u60a8\u60f3\u8981\u5b89\u88c5\u7684\u5e93\u540d\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Termux\u4e2d\u5b89\u88c5\u548c\u4f7f\u7528Python\u7684\u6b65\u9aa4\u5305\u62ec\uff1a\u5b89\u88c5Termux\u3001\u66f4\u65b0\u8f6f\u4ef6\u5305\u3001\u5b89\u88c5Python\u3001\u9a8c\u8bc1\u5b89\u88c5\u3001\u4f7f [&hellip;]","protected":false},"author":3,"featured_media":925116,"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\/925108"}],"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=925108"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/925108\/revisions"}],"predecessor-version":[{"id":925117,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/925108\/revisions\/925117"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/925116"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=925108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=925108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=925108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}