{"id":1002360,"date":"2024-12-27T10:08:03","date_gmt":"2024-12-27T02:08:03","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1002360.html"},"modified":"2024-12-27T10:08:05","modified_gmt":"2024-12-27T02:08:05","slug":"termux%e4%b8%ad%e5%a6%82%e4%bd%95%e9%80%80%e5%87%bapython","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1002360.html","title":{"rendered":"termux\u4e2d\u5982\u4f55\u9000\u51fapython"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25080143\/049ce1c1-e55f-479e-a1b2-e633fc58c4ec.webp\" alt=\"termux\u4e2d\u5982\u4f55\u9000\u51fapython\" \/><\/p>\n<p><p> \u5728Termux\u4e2d\u9000\u51faPython\u89e3\u91ca\u5668\u7684\u5e38\u7528\u65b9\u6cd5\u6709\u4ee5\u4e0b\u51e0\u79cd\uff1a<strong>\u4f7f\u7528<code>exit()<\/code>\u547d\u4ee4\u3001\u4f7f\u7528\u5feb\u6377\u952e\u7ec4\u5408<code>Ctrl+D<\/code>\u3001\u4f7f\u7528<code>quit()<\/code>\u547d\u4ee4<\/strong>\u3002\u5728\u8fd9\u51e0\u79cd\u65b9\u6cd5\u4e2d\uff0c\u4f7f\u7528\u5feb\u6377\u952e\u7ec4\u5408<code>Ctrl+D<\/code>\u662f\u6700\u4e3a\u7b80\u4fbf\u548c\u5e38\u7528\u7684\u3002\u4e0b\u9762\u5c06\u8be6\u7ec6\u89e3\u91ca\u6bcf\u79cd\u65b9\u6cd5\u4ee5\u53ca\u4e00\u4e9b\u76f8\u5173\u7684\u6ce8\u610f\u4e8b\u9879\u548c\u80cc\u666f\u77e5\u8bc6\u3002<\/p>\n<\/p>\n<p><p>\u4e00\u3001\u4f7f\u7528<code>exit()<\/code>\u547d\u4ee4<\/p>\n<\/p>\n<p><p>\u5728Python\u4ea4\u4e92\u6a21\u5f0f\u4e0b\uff0c<code>exit()<\/code>\u547d\u4ee4\u662f\u6700\u5e38\u7528\u7684\u9000\u51fa\u65b9\u6cd5\u4e4b\u4e00\u3002\u8f93\u5165<code>exit()<\/code>\u5e76\u6309\u4e0b\u56de\u8f66\uff0cPython\u89e3\u91ca\u5668\u5c06\u4f1a\u7ec8\u6b62\u5f53\u524d\u7684\u4f1a\u8bdd\u5e76\u8fd4\u56de\u5230Termux\u7684\u547d\u4ee4\u884c\u754c\u9762\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528\u65b9\u6cd5<\/strong><\/p>\n<\/p>\n<p><p>\u5728Termux\u4e2d\u542f\u52a8Python\u89e3\u91ca\u5668\u540e\uff0c\u4f60\u4f1a\u770b\u5230\u7c7b\u4f3c\u4e8e<code>&gt;&gt;&gt;<\/code>\u8fd9\u6837\u7684\u63d0\u793a\u7b26\u3002\u8981\u9000\u51faPython\uff0c\u53ea\u9700\u5728\u63d0\u793a\u7b26\u540e\u8f93\u5165<code>exit()<\/code>\u5e76\u6309\u4e0b\u56de\u8f66\u952e\u5373\u53ef\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u786e\u4fdd\u62ec\u53f7<code>()<\/code>\u4e0d\u6f0f\u6389\uff0c\u5426\u5219Python\u4f1a\u62a5\u9519\u3002<\/li>\n<li>\u5982\u679c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b<code>exit()<\/code>\u547d\u4ee4\u65e0\u6548\uff0c\u53ef\u80fd\u662f\u56e0\u4e3a\u4ee3\u7801\u5757\u672a\u5b8c\u6210\u6216\u51fa\u73b0\u8bed\u6cd5\u9519\u8bef\uff0c\u8fd9\u65f6\u5019\u9700\u8981\u68c0\u67e5\u4ee3\u7801\u5b8c\u6574\u6027\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u80cc\u666f\u77e5\u8bc6<\/strong><\/p>\n<\/p>\n<p><p><code>exit()<\/code>\u662fPython\u5185\u7f6e\u7684\u51fd\u6570\uff0c\u901a\u5e38\u7528\u4e8e\u5728\u4ea4\u4e92\u6a21\u5f0f\u4e0b\u6216\u811a\u672c\u4e2d\u7ec8\u6b62\u7a0b\u5e8f\u3002\u867d\u7136\u5728\u811a\u672c\u4e2d\u4f7f\u7528\u4e0d\u5e38\u89c1\uff0c\u4f46\u5728\u4ea4\u4e92\u6a21\u5f0f\u4e0b\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e8c\u3001\u4f7f\u7528\u5feb\u6377\u952e\u7ec4\u5408<code>Ctrl+D<\/code><\/p>\n<\/p>\n<p><p><code>Ctrl+D<\/code>\u662fUnix\/Linux\u7cfb\u7edf\u4e2d\u5e38\u7528\u7684\u7ed3\u675f\u8f93\u5165\u4fe1\u53f7\uff0c\u5728Python\u89e3\u91ca\u5668\u4e2d\u4e5f\u53ef\u4ee5\u7528\u6765\u9000\u51fa\u5f53\u524d\u4f1a\u8bdd\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528\u65b9\u6cd5<\/strong><\/p>\n<\/p>\n<p><p>\u5728Python\u89e3\u91ca\u5668\u4e2d\uff0c\u6309\u4e0b<code>Ctrl<\/code>\u952e\u4e0d\u653e\uff0c\u7136\u540e\u6309<code>D<\/code>\u952e\uff0c\u89e3\u91ca\u5668\u4f1a\u7acb\u5373\u9000\u51fa\u5e76\u8fd4\u56de\u5230\u547d\u4ee4\u884c\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f18\u70b9<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u5feb\u6377\u65b9\u4fbf\uff0c\u4e0d\u9700\u8981\u8f93\u5165\u4efb\u4f55\u547d\u4ee4\u3002<\/li>\n<li>\u5373\u4f7f\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b<code>exit()<\/code>\u548c<code>quit()<\/code>\u547d\u4ee4\u5931\u6548\uff0c<code>Ctrl+D<\/code>\u901a\u5e38\u4f9d\u7136\u6709\u6548\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<\/p>\n<ul>\n<li>\u786e\u4fdd\u5f53\u524d\u5904\u4e8ePython\u89e3\u91ca\u5668\u7684\u9876\u5c42\uff0c\u800c\u4e0d\u662f\u5728\u4e00\u4e2a\u672a\u5b8c\u6210\u7684\u4ee3\u7801\u5757\u4e2d\u3002<\/li>\n<li>\u8be5\u7ec4\u5408\u952e\u5728Unix\/Linux\u7cfb\u7edf\u4e2d\u666e\u904d\u9002\u7528\uff0c\u4f46\u5728\u67d0\u4e9b\u56fe\u5f62\u5316\u7ec8\u7aef\u6216\u7279\u5b9a\u8bbe\u7f6e\u4e0b\u53ef\u80fd\u4f1a\u88ab\u91cd\u65b0\u5b9a\u4e49\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p><p>\u4e09\u3001\u4f7f\u7528<code>quit()<\/code>\u547d\u4ee4<\/p>\n<\/p>\n<p><p><code>quit()<\/code>\u547d\u4ee4\u4e0e<code>exit()<\/code>\u547d\u4ee4\u529f\u80fd\u76f8\u540c\uff0c\u4e5f\u662f\u7528\u4e8e\u9000\u51faPython\u89e3\u91ca\u5668\u3002<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u4f7f\u7528\u65b9\u6cd5<\/strong><\/p>\n<\/p>\n<p><p>\u4e0e<code>exit()<\/code>\u76f8\u540c\uff0c\u5728\u63d0\u793a\u7b26\u540e\u8f93\u5165<code>quit()<\/code>\u5e76\u6309\u56de\u8f66\u5373\u53ef\u9000\u51fa\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u80cc\u666f\u77e5\u8bc6<\/strong><\/p>\n<\/p>\n<p><p><code>quit()<\/code>\u548c<code>exit()<\/code>\u7684\u5b9e\u73b0\u539f\u7406\u76f8\u540c\uff0c\u901a\u5e38\u90fd\u662f\u901a\u8fc7\u8c03\u7528<code>sys.exit()<\/code>\u6765\u5b9e\u73b0\u9000\u51fa\u529f\u80fd\u3002\u8fd9\u4e24\u4e2a\u547d\u4ee4\u5728Python Shell\u4e2d\u4f5c\u7528\u4e00\u81f4\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u56db\u3001\u5176\u4ed6\u76f8\u5173\u6280\u5de7\u548c\u6ce8\u610f\u4e8b\u9879<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u68c0\u67e5\u672a\u5b8c\u6210\u7684\u4ee3\u7801\u5757<\/strong><\/p>\n<\/p>\n<p><p>\u6709\u65f6\u5019\u4f60\u4f1a\u53d1\u73b0<code>exit()<\/code>\u6216<code>quit()<\/code>\u547d\u4ee4\u65e0\u6548\uff0c\u8fd9\u901a\u5e38\u662f\u56e0\u4e3a\u5b58\u5728\u672a\u5b8c\u6210\u7684\u4ee3\u7801\u5757\u3002\u6bd4\u5982\uff0c\u4f60\u53ef\u80fd\u5728\u5b9a\u4e49\u4e00\u4e2a\u591a\u884c\u51fd\u6570\u6216\u7c7b\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\u9700\u8981\u5b8c\u6210\u4ee3\u7801\u5757\u6216\u4f7f\u7528<code>Ctrl+C<\/code>\u4e2d\u65ad\u5f53\u524d\u8f93\u5165\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528<code>sys.exit()<\/code><\/strong><\/p>\n<\/p>\n<p><p>\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u7279\u522b\u662f\u7f16\u5199Python\u811a\u672c\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528<code>sys.exit()<\/code>\u6765\u9000\u51fa\u7a0b\u5e8f\u3002\u9700\u8981\u6ce8\u610f\u7684\u662f\uff0c\u4f7f\u7528<code>sys.exit()<\/code>\u65f6\u9700\u8981\u5148\u5bfc\u5165<code>sys<\/code>\u6a21\u5757\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u907f\u514d\u8bef\u64cd\u4f5c<\/strong><\/p>\n<\/p>\n<p><p>\u5982\u679c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u4e0d\u5c0f\u5fc3\u9000\u51fa\u4e86Python\u89e3\u91ca\u5668\uff0c\u800c\u4f60\u7684\u5de5\u4f5c\u672a\u4fdd\u5b58\uff0c\u53ef\u4ee5\u901a\u8fc7\u5386\u53f2\u8bb0\u5f55\u627e\u56de\u4e4b\u524d\u7684\u547d\u4ee4\u3002\u5728Termux\u4e2d\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u6309\u4e0a\u7bad\u5934\u952e\u67e5\u770b\u547d\u4ee4\u5386\u53f2\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u4e94\u3001\u5728Termux\u4e2d\u4f7f\u7528Python\u7684\u989d\u5916\u63d0\u793a<\/p>\n<\/p>\n<ol>\n<li>\n<p><strong>\u5b89\u88c5Python<\/strong><\/p>\n<\/p>\n<p><p>\u5728Termux\u4e2d\u4f7f\u7528Python\u4e4b\u524d\uff0c\u9700\u8981\u786e\u4fddPython\u5df2\u6b63\u786e\u5b89\u88c5\u3002\u53ef\u4ee5\u901a\u8fc7\u6267\u884c\u547d\u4ee4<code>pkg install python<\/code>\u6765\u5b89\u88c5Python\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u66f4\u65b0Python<\/strong><\/p>\n<\/p>\n<p><p>\u786e\u4fdd\u4f60\u7684Python\u7248\u672c\u662f\u6700\u65b0\u7684\uff0c\u4ee5\u4fbf\u83b7\u5f97\u6700\u65b0\u7684\u529f\u80fd\u548c\u5b89\u5168\u66f4\u65b0\u3002\u53ef\u4ee5\u901a\u8fc7<code>pkg upgrade python<\/code>\u6765\u66f4\u65b0\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u4f7f\u7528Python\u865a\u62df\u73af\u5883<\/strong><\/p>\n<\/p>\n<p><p>\u5728Termux\u4e2d\u5f00\u53d1Python\u9879\u76ee\u65f6\uff0c\u5efa\u8bae\u4f7f\u7528\u865a\u62df\u73af\u5883\u6765\u7ba1\u7406\u4f9d\u8d56\u3002\u53ef\u4ee5\u4f7f\u7528<code>python -m venv myenv<\/code>\u547d\u4ee4\u521b\u5efa\u865a\u62df\u73af\u5883\uff0c\u7136\u540e\u901a\u8fc7<code>source myenv\/bin\/activate<\/code>\u6fc0\u6d3b\u3002<\/p>\n<\/p>\n<\/li>\n<li>\n<p><strong>\u7ba1\u7406Python\u5305<\/strong><\/p>\n<\/p>\n<p><p>\u4f7f\u7528<code>pip<\/code>\u547d\u4ee4\u6765\u7ba1\u7406Python\u5305\uff0c\u4f8b\u5982<code>pip install package_name<\/code>\u6765\u5b89\u88c5\u5305\u3002\u5728Termux\u4e2d\uff0c\u786e\u4fdd\u7f51\u7edc\u8fde\u63a5\u826f\u597d\u4ee5\u4fbf\u6210\u529f\u5b89\u88c5\u3002<\/p>\n<\/p>\n<\/li>\n<\/ol>\n<p><p>\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\u548c\u6280\u5de7\uff0c\u4f60\u53ef\u4ee5\u8f7b\u677e\u5730\u5728Termux\u4e2d\u7ba1\u7406Python\u4f1a\u8bdd\uff0c\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u5e76\u907f\u514d\u5e38\u89c1\u95ee\u9898\u3002\u5e0c\u671b\u8fd9\u4e9b\u4fe1\u606f\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff01<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Termux\u4e2d\u5b89\u5168\u9000\u51faPython\u73af\u5883\uff1f<\/strong><br \/>\u5728Termux\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u8f93\u5165<code>exit()<\/code>\u6216\u4f7f\u7528Ctrl + D\u7ec4\u5408\u952e\u6765\u5b89\u5168\u9000\u51faPython\u4ea4\u4e92\u5f0f\u73af\u5883\u3002\u8fd9\u4e24\u79cd\u65b9\u5f0f\u90fd\u4f1a\u6b63\u5e38\u5173\u95edPython\u4f1a\u8bdd\uff0c\u786e\u4fdd\u6240\u6709\u672a\u4fdd\u5b58\u7684\u6570\u636e\u90fd\u4e0d\u4f1a\u4e22\u5931\u3002<\/p>\n<p><strong>\u5728Termux\u4e2d\u4f7f\u7528Python\u65f6\u9047\u5230\u95ee\u9898\uff0c\u600e\u6837\u67e5\u770b\u5e2e\u52a9\u6587\u6863\uff1f<\/strong><br \/>\u5982\u679c\u5728Termux\u4e2d\u4f7f\u7528Python\u65f6\u9047\u5230\u95ee\u9898\uff0c\u53ef\u4ee5\u901a\u8fc7\u8f93\u5165<code>help()<\/code>\u547d\u4ee4\u6765\u83b7\u53d6\u57fa\u672c\u7684\u5e2e\u52a9\u4fe1\u606f\u3002\u6b64\u5916\uff0cPython\u7684\u5b98\u65b9\u7f51\u7ad9\u548c\u5728\u7ebf\u6587\u6863\u63d0\u4f9b\u4e86\u66f4\u8be6\u7ec6\u7684\u6307\u5357\u548c\u793a\u4f8b\uff0c\u5e2e\u52a9\u7528\u6237\u89e3\u51b3\u5e38\u89c1\u95ee\u9898\u3002<\/p>\n<p><strong>\u4e3a\u4ec0\u4e48\u5728Termux\u4e2d\u9000\u51faPython\u540e\u4f1a\u770b\u5230\u63d0\u793a\u7b26\uff1f<\/strong><br \/>\u9000\u51faPython\u540e\uff0c\u7528\u6237\u4f1a\u8fd4\u56de\u5230Termux\u7684\u547d\u4ee4\u884c\u754c\u9762\uff0c\u663e\u793a\u7cfb\u7edf\u7684\u63d0\u793a\u7b26\u3002\u8fd9\u662f\u56e0\u4e3aPython\u73af\u5883\u88ab\u5173\u95ed\uff0c\u7528\u6237\u73b0\u5728\u53ef\u4ee5\u6267\u884c\u5176\u4ed6Shell\u547d\u4ee4\u3002\u6b64\u65f6\u53ef\u4ee5\u7ee7\u7eed\u4f7f\u7528Termux\u8fdb\u884c\u5176\u4ed6\u64cd\u4f5c\uff0c\u5982\u5b89\u88c5\u8f6f\u4ef6\u5305\u6216\u8fd0\u884c\u811a\u672c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Termux\u4e2d\u9000\u51faPython\u89e3\u91ca\u5668\u7684\u5e38\u7528\u65b9\u6cd5\u6709\u4ee5\u4e0b\u51e0\u79cd\uff1a\u4f7f\u7528exit()\u547d\u4ee4\u3001\u4f7f\u7528\u5feb\u6377\u952e\u7ec4\u5408Ctrl+D\u3001 [&hellip;]","protected":false},"author":3,"featured_media":1002369,"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\/1002360"}],"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=1002360"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1002360\/revisions"}],"predecessor-version":[{"id":1002372,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1002360\/revisions\/1002372"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1002369"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1002360"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1002360"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1002360"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}