{"id":1155698,"date":"2025-01-13T18:06:52","date_gmt":"2025-01-13T10:06:52","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1155698.html"},"modified":"2025-01-13T18:06:55","modified_gmt":"2025-01-13T10:06:55","slug":"termux%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8python%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1155698.html","title":{"rendered":"termux\u5982\u4f55\u4f7f\u7528python\u6559\u7a0b"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25194240\/704762bb-1cea-4d87-a5d2-7fc566e74947.webp\" alt=\"termux\u5982\u4f55\u4f7f\u7528python\u6559\u7a0b\" \/><\/p>\n<p><p> \u5f00\u5934\u6bb5\u843d\uff1a<\/p>\n<p><strong>\u5728Termux\u4e2d\u4f7f\u7528Python\uff0c\u4e3b\u8981\u6b65\u9aa4\u5305\u62ec\u5b89\u88c5Termux\u3001\u5b89\u88c5Python\u3001\u914d\u7f6e\u73af\u5883\u3001\u5b89\u88c5\u6240\u9700\u5e93\u3001\u7f16\u5199\u5e76\u8fd0\u884cPython\u811a\u672c\u3002<\/strong>\u5176\u4e2d\uff0c\u5b89\u88c5Python\u662f\u6700\u4e3a\u5173\u952e\u7684\u4e00\u6b65\uff0c\u56e0\u4e3a\u5b83\u51b3\u5b9a\u4e86\u540e\u7eed\u914d\u7f6e\u73af\u5883\u548c\u5b89\u88c5\u5e93\u7684\u987a\u5229\u8fdb\u884c\u3002\u786e\u4fddPython\u5b89\u88c5\u6b63\u786e\u5e76\u80fd\u8fd0\u884c\u540e\uff0c\u6211\u4eec\u53ef\u4ee5\u7ee7\u7eed\u8fdb\u884c\u5176\u4ed6\u6b65\u9aa4\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u5b89\u88c5Termux<\/h3>\n<\/p>\n<p><p>Termux\u662f\u4e00\u6b3e\u5728Android\u8bbe\u5907\u4e0a\u8fd0\u884c\u7684\u7ec8\u7aef\u4eff\u771f\u5668\uff0c\u53ef\u4ee5\u6a21\u62dfLinux\u73af\u5883\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e2a\u5f3a\u5927\u7684\u5de5\u5177\u96c6\u5408\uff0c\u9002\u5408\u5f00\u53d1\u8005\u548c\u6280\u672f\u7231\u597d\u8005\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><h4>1. \u4e0b\u8f7d\u548c\u5b89\u88c5<\/h4>\n<\/p>\n<p><p>\u8981\u5f00\u59cb\u4f7f\u7528Termux\uff0c\u9996\u5148\u9700\u8981\u4eceGoogle Play\u5546\u5e97\u6216\u8005\u5176\u4ed6\u53ef\u4fe1\u7684APK\u6765\u6e90\u4e0b\u8f7d\u5e76\u5b89\u88c5Termux\u5e94\u7528\u3002\u6253\u5f00\u5e94\u7528\u5546\u5e97\uff0c\u641c\u7d22\u201cTermux\u201d\uff0c\u7136\u540e\u70b9\u51fb\u5b89\u88c5\u3002<\/p>\n<\/p>\n<p><h4>2. \u521d\u59cb\u8bbe\u7f6e<\/h4>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u6253\u5f00Termux\u3002\u9996\u6b21\u542f\u52a8\u65f6\uff0c\u5b83\u4f1a\u81ea\u52a8\u66f4\u65b0\u5e76\u5b89\u88c5\u4e00\u4e9b\u5fc5\u8981\u7684\u7ec4\u4ef6\u3002\u7b49\u5f85\u8fd9\u4e9b\u64cd\u4f5c\u5b8c\u6210\uff0c\u7136\u540e\u4f60\u4f1a\u770b\u5230\u4e00\u4e2a\u7c7b\u4f3c\u4e8eLinux\u7ec8\u7aef\u7684\u754c\u9762\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u5b89\u88c5Python<\/h3>\n<\/p>\n<p><p>\u5728Termux\u4e2d\uff0c\u5b89\u88c5Python\u975e\u5e38\u7b80\u5355\u3002Termux\u7684\u5305\u7ba1\u7406\u5668apt\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u8f7b\u677e\u5b89\u88c5\u5404\u79cd\u8f6f\u4ef6\u5305\uff0c\u5305\u62ecPython\u3002<\/p>\n<\/p>\n<p><h4>1. \u66f4\u65b0\u548c\u5347\u7ea7\u5305\u7ba1\u7406\u5668<\/h4>\n<\/p>\n<p><p>\u5728\u5b89\u88c5Python\u4e4b\u524d\uff0c\u5efa\u8bae\u5148\u66f4\u65b0\u548c\u5347\u7ea7Termux\u7684\u5305\u7ba1\u7406\u5668\uff0c\u4ee5\u786e\u4fdd\u6240\u6709\u8f6f\u4ef6\u5305\u662f\u6700\u65b0\u7684\u3002\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<\/p>\n<p><pre><code>pkg update<\/p>\n<p>pkg upgrade<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u5b89\u88c5Python<\/h4>\n<\/p>\n<p><p>\u66f4\u65b0\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5Python\uff1a<\/p>\n<\/p>\n<p><pre><code>pkg install python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7cfb\u7edf\u4f1a\u63d0\u793a\u4f60\u786e\u8ba4\u5b89\u88c5\uff0c\u8f93\u5165\u201cy\u201d\u5e76\u6309\u4e0b\u56de\u8f66\u952e\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u9a8c\u8bc1Python\u662f\u5426\u5b89\u88c5\u6210\u529f\uff1a<\/p>\n<\/p>\n<p><pre><code>python --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u770b\u5230\u7c7b\u4f3c\u201cPython 3.x.x\u201d\u7684\u8f93\u51fa\uff0c\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u914d\u7f6e\u73af\u5883<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u5728Termux\u4e2d\u66f4\u65b9\u4fbf\u5730\u4f7f\u7528Python\uff0c\u6211\u4eec\u53ef\u4ee5\u914d\u7f6e\u4e00\u4e9b\u73af\u5883\u53d8\u91cf\u548c\u5b89\u88c5\u5e38\u7528\u7684\u5de5\u5177\u3002<\/p>\n<\/p>\n<p><h4>1. \u8bbe\u7f6ePython\u73af\u5883\u53d8\u91cf<\/h4>\n<\/p>\n<p><p>\u867d\u7136\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u9ed8\u8ba4\u7684Python\u73af\u5883\u5df2\u7ecf\u8db3\u591f\u4f7f\u7528\uff0c\u4f46\u5728\u67d0\u4e9b\u7279\u5b9a\u573a\u666f\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u624b\u52a8\u914d\u7f6e\u73af\u5883\u53d8\u91cf\u3002\u4f8b\u5982\uff0c\u7f16\u8f91<code>.bashrc<\/code>\u6587\u4ef6\u6765\u8bbe\u7f6ePython\u8def\u5f84\uff1a<\/p>\n<\/p>\n<p><pre><code>nano ~\/.bashrc<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u6587\u4ef6\u672b\u5c3e\u6dfb\u52a0\uff1a<\/p>\n<\/p>\n<p><pre><code>export PATH=$PATH:\/data\/data\/com.termux\/files\/usr\/bin\/python<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4fdd\u5b58\u5e76\u9000\u51fa\uff0c\u7136\u540e\u8fd0\u884c\uff1a<\/p>\n<\/p>\n<p><pre><code>source ~\/.bashrc<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u5b89\u88c5pip<\/h4>\n<\/p>\n<p><p>pip\u662fPython\u7684\u5305\u7ba1\u7406\u5668\uff0c\u7528\u4e8e\u5b89\u88c5\u548c\u7ba1\u7406Python\u5e93\u3002\u5728Termux\u4e2d\u5b89\u88c5pip\u975e\u5e38\u7b80\u5355\uff1a<\/p>\n<\/p>\n<p><pre><code>pkg install python-pip<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9a8c\u8bc1pip\u662f\u5426\u5b89\u88c5\u6210\u529f\uff1a<\/p>\n<\/p>\n<p><pre><code>pip --version<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u770b\u5230\u7c7b\u4f3c\u201cpip 20.x.x\u201d\u7684\u8f93\u51fa\uff0c\u8bf4\u660e\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001\u5b89\u88c5\u6240\u9700\u5e93<\/h3>\n<\/p>\n<p><p>\u5728Python\u5f00\u53d1\u4e2d\uff0c\u901a\u5e38\u9700\u8981\u5404\u79cd\u7b2c\u4e09\u65b9\u5e93\u6765\u8f85\u52a9\u5f00\u53d1\u3002\u53ef\u4ee5\u4f7f\u7528pip\u6765\u5b89\u88c5\u8fd9\u4e9b\u5e93\u3002<\/p>\n<\/p>\n<p><h4>1. \u5e38\u7528\u5e93\u7684\u5b89\u88c5<\/h4>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u5b89\u88c5NumPy\u548cPandas\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code>pip install numpy<\/p>\n<p>pip install pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u8fc7\u7a0b\u4e2d\uff0cpip\u4f1a\u81ea\u52a8\u5904\u7406\u4f9d\u8d56\u5173\u7cfb\uff0c\u786e\u4fdd\u6240\u6709\u5fc5\u8981\u7684\u5e93\u90fd\u88ab\u5b89\u88c5\u3002<\/p>\n<\/p>\n<p><h4>2. \u68c0\u67e5\u5b89\u88c5\u7ed3\u679c<\/h4>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u547d\u4ee4\u6765\u68c0\u67e5\u5e93\u662f\u5426\u5b89\u88c5\u6210\u529f\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">python<\/p>\n<p>&gt;&gt;&gt; import numpy<\/p>\n<p>&gt;&gt;&gt; import pandas<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u6ca1\u6709\u9519\u8bef\u63d0\u793a\uff0c\u8bf4\u660e\u5e93\u5b89\u88c5\u6210\u529f\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u7f16\u5199\u5e76\u8fd0\u884cPython\u811a\u672c<\/h3>\n<\/p>\n<p><p>\u5728Termux\u4e2d\u7f16\u5199\u548c\u8fd0\u884cPython\u811a\u672c\u975e\u5e38\u7b80\u5355\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528Termux\u5185\u7f6e\u7684\u6587\u672c\u7f16\u8f91\u5668\uff08\u5982nano\uff09\u6765\u7f16\u5199\u811a\u672c\u3002<\/p>\n<\/p>\n<p><h4>1. \u521b\u5efa\u811a\u672c\u6587\u4ef6<\/h4>\n<\/p>\n<p><p>\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>hello.py<\/code>\u7684Python\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code>nano hello.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u6587\u4ef6\u4e2d\u8f93\u5165\u4ee5\u4e0b\u5185\u5bb9\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\u51fa\uff08\u6309<code>Ctrl+X<\/code>\uff0c\u7136\u540e\u6309<code>Y<\/code>\u786e\u8ba4\u4fdd\u5b58\uff09\u3002<\/p>\n<\/p>\n<p><h4>2. \u8fd0\u884c\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u6267\u884c\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code>python hello.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u4f60\u4f1a\u770b\u5230\u8f93\u51fa\u201cHello, Termux!\u201d\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u4f7f\u7528Jupyter Notebook<\/h3>\n<\/p>\n<p><p>Jupyter Notebook\u662f\u4e00\u4e2a\u975e\u5e38\u6d41\u884c\u7684Python\u4ea4\u4e92\u5f0f\u5f00\u53d1\u73af\u5883\uff0c\u53ef\u4ee5\u5728Termux\u4e2d\u5b89\u88c5\u548c\u4f7f\u7528\u3002<\/p>\n<\/p>\n<p><h4>1. \u5b89\u88c5Jupyter Notebook<\/h4>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u5b89\u88c5\u6240\u9700\u7684\u4f9d\u8d56\uff1a<\/p>\n<\/p>\n<p><pre><code>pkg install libzmq libcrypt<\/p>\n<p>pip install jupyter<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u542f\u52a8Jupyter Notebook<\/h4>\n<\/p>\n<p><p>\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u542f\u52a8Jupyter Notebook\uff1a<\/p>\n<\/p>\n<p><pre><code>jupyter notebook --ip=0.0.0.0 --port=8888 --no-browser<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>Jupyter Notebook\u5c06\u542f\u52a8\u5e76\u5728\u7ec8\u7aef\u4e2d\u663e\u793a\u8bbf\u95eeURL\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u624b\u673a\u4e0a\u7684\u6d4f\u89c8\u5668\u8bbf\u95ee\u8fd9\u4e2aURL\u6765\u4f7f\u7528Jupyter Notebook\u3002<\/p>\n<\/p>\n<p><h3>\u4e03\u3001\u8c03\u8bd5\u548c\u6d4b\u8bd5<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u8c03\u8bd5\u548c\u6d4b\u8bd5\u662f\u975e\u5e38\u91cd\u8981\u7684\u73af\u8282\u3002Python\u63d0\u4f9b\u4e86\u591a\u79cd\u8c03\u8bd5\u5de5\u5177\u548c\u6d4b\u8bd5\u6846\u67b6\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528\u5185\u7f6e\u8c03\u8bd5\u5668<\/h4>\n<\/p>\n<p><p>Python\u7684\u5185\u7f6e\u8c03\u8bd5\u5668pdb\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u9010\u884c\u8c03\u8bd5\u4ee3\u7801\u3002\u53ef\u4ee5\u5728\u811a\u672c\u4e2d\u63d2\u5165\u4ee5\u4e0b\u4ee3\u7801\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>\u8fd0\u884c\u811a\u672c\u65f6\uff0c\u8c03\u8bd5\u5668\u4f1a\u5728\u8fd9\u4e00\u884c\u542f\u52a8\uff0c\u5141\u8bb8\u4f60\u9010\u884c\u68c0\u67e5\u4ee3\u7801\u6267\u884c\u60c5\u51b5\u3002<\/p>\n<\/p>\n<p><h4>2. \u7f16\u5199\u5355\u5143\u6d4b\u8bd5<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528unittest\u6a21\u5757\u7f16\u5199\u5355\u5143\u6d4b\u8bd5\u6765\u786e\u4fdd\u4ee3\u7801\u7684\u6b63\u786e\u6027\u3002\u4f8b\u5982\uff0c\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a<code>test.py<\/code>\u7684\u6d4b\u8bd5\u6587\u4ef6\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import unittest<\/p>\n<p>def add(a, b):<\/p>\n<p>    return a + b<\/p>\n<p>class TestAddFunction(unittest.TestCase):<\/p>\n<p>    def test_add(self):<\/p>\n<p>        self.assertEqual(add(1, 2), 3)<\/p>\n<p>if __name__ == &#39;__m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n__&#39;:<\/p>\n<p>    unittest.main()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u7ec8\u7aef\u4e2d\u8fd0\u884c\u6d4b\u8bd5\uff1a<\/p>\n<\/p>\n<p><pre><code>python test.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5982\u679c\u6240\u6709\u6d4b\u8bd5\u901a\u8fc7\uff0c\u4f60\u4f1a\u770b\u5230\u201cOK\u201d\u7684\u8f93\u51fa\u3002<\/p>\n<\/p>\n<p><h3>\u516b\u3001\u7ba1\u7406\u9879\u76ee\u4f9d\u8d56<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u53d1\u590d\u6742\u9879\u76ee\u65f6\uff0c\u7ba1\u7406\u9879\u76ee\u4f9d\u8d56\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u53ef\u4ee5\u4f7f\u7528<code>requirements.txt<\/code>\u6587\u4ef6\u6765\u8bb0\u5f55\u9879\u76ee\u6240\u9700\u7684\u6240\u6709\u5e93\u3002<\/p>\n<\/p>\n<p><h4>1. \u751f\u6210requirements.txt<\/h4>\n<\/p>\n<p><p>\u5728\u9879\u76ee\u76ee\u5f55\u4e2d\u8fd0\u884c\u4ee5\u4e0b\u547d\u4ee4\u6765\u751f\u6210<code>requirements.txt<\/code>\uff1a<\/p>\n<\/p>\n<p><pre><code>pip freeze &gt; requirements.txt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u6587\u4ef6\u4f1a\u5217\u51fa\u9879\u76ee\u6240\u9700\u7684\u6240\u6709\u5e93\u53ca\u5176\u7248\u672c\u3002<\/p>\n<\/p>\n<p><h4>2. \u5b89\u88c5\u9879\u76ee\u4f9d\u8d56<\/h4>\n<\/p>\n<p><p>\u5f53\u4f60\u5728\u65b0\u7684\u73af\u5883\u4e2d\u8fd0\u884c\u9879\u76ee\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u5b89\u88c5\u6240\u6709\u4f9d\u8d56\uff1a<\/p>\n<\/p>\n<p><pre><code>pip install -r requirements.txt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u786e\u4fdd\u65b0\u73af\u5883\u4e2d\u5b89\u88c5\u7684\u5e93\u7248\u672c\u4e0e\u5f00\u53d1\u73af\u5883\u4e00\u81f4\u3002<\/p>\n<\/p>\n<p><h3>\u4e5d\u3001\u8fdc\u7a0b\u5f00\u53d1\u548c\u7248\u672c\u63a7\u5236<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u53d1\u8fc7\u7a0b\u4e2d\uff0c\u4f7f\u7528\u7248\u672c\u63a7\u5236\u5de5\u5177\uff08\u5982Git\uff09\u548c\u8fdc\u7a0b\u5f00\u53d1\u5de5\u5177\uff08\u5982SSH\uff09\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<\/p>\n<p><h4>1. \u5b89\u88c5\u548c\u914d\u7f6eGit<\/h4>\n<\/p>\n<p><p>\u5728Termux\u4e2d\u5b89\u88c5Git\u975e\u5e38\u7b80\u5355\uff1a<\/p>\n<\/p>\n<p><pre><code>pkg install git<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u914d\u7f6e\u7528\u6237\u540d\u548c\u90ae\u7bb1\uff1a<\/p>\n<\/p>\n<p><pre><code>git config --global user.name &quot;Your Name&quot;<\/p>\n<p>git config --global user.email &quot;your.email@example.com&quot;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528SSH\u8fdb\u884c\u8fdc\u7a0b\u5f00\u53d1<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4f7f\u7528SSH\u8fde\u63a5\u5230\u8fdc\u7a0b\u670d\u52a1\u5668\u8fdb\u884c\u5f00\u53d1\u3002\u9996\u5148\uff0c\u751f\u6210SSH\u5bc6\u94a5\uff1a<\/p>\n<\/p>\n<p><pre><code>ssh-keygen -t rsa -b 2048<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u5c06\u516c\u94a5\u6dfb\u52a0\u5230\u8fdc\u7a0b\u670d\u52a1\u5668\u7684<code>~\/.ssh\/authorized_keys<\/code>\u6587\u4ef6\u4e2d\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fde\u63a5\u5230\u8fdc\u7a0b\u670d\u52a1\u5668\uff1a<\/p>\n<\/p>\n<p><pre><code>ssh user@remote_server<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u3001\u6027\u80fd\u4f18\u5316\u548c\u9ad8\u7ea7\u6280\u5de7<\/h3>\n<\/p>\n<p><p>\u4e3a\u4e86\u63d0\u9ad8Python\u811a\u672c\u7684\u6027\u80fd\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u4f18\u5316\u6280\u5de7\u548c\u5de5\u5177\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528Cython\u52a0\u901f<\/h4>\n<\/p>\n<p><p>Cython\u662f\u4e00\u79cd\u5c06Python\u4ee3\u7801\u7f16\u8bd1\u6210C\u4ee3\u7801\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u663e\u8457\u63d0\u9ad8\u4ee3\u7801\u7684\u6267\u884c\u901f\u5ea6\u3002\u5b89\u88c5Cython\uff1a<\/p>\n<\/p>\n<p><pre><code>pip install cython<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u5c06Python\u4ee3\u7801\u8f6c\u6362\u4e3aCython\u4ee3\u7801\u5e76\u7f16\u8bd1\uff1a<\/p>\n<\/p>\n<p><pre><code>cythonize -i your_script.pyx<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528\u591a\u7ebf\u7a0b\u548c\u591a\u8fdb\u7a0b<\/h4>\n<\/p>\n<p><p>Python\u7684<code>threading<\/code>\u548c<code>multiprocessing<\/code>\u6a21\u5757\u53ef\u4ee5\u5e2e\u52a9\u6211\u4eec\u5229\u7528\u591a\u6838CPU\u6765\u63d0\u9ad8\u5e76\u53d1\u6027\u80fd\u3002\u4f8b\u5982\uff0c\u4f7f\u7528<code>multiprocessing<\/code>\u6a21\u5757\u6765\u521b\u5efa\u591a\u4e2a\u8fdb\u7a0b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from multiprocessing import Process<\/p>\n<p>def worker(num):<\/p>\n<p>    print(f&quot;Worker: {num}&quot;)<\/p>\n<p>if __name__ == &quot;__main__&quot;:<\/p>\n<p>    processes = []<\/p>\n<p>    for i in range(5):<\/p>\n<p>        p = Process(target=worker, args=(i,))<\/p>\n<p>        processes.append(p)<\/p>\n<p>        p.start()<\/p>\n<p>    for p in processes:<\/p>\n<p>        p.join()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u811a\u672c\u4f1a\u521b\u5efa\u5e76\u542f\u52a8\u4e94\u4e2a\u8fdb\u7a0b\uff0c\u6bcf\u4e2a\u8fdb\u7a0b\u90fd\u4f1a\u8f93\u51fa\u81ea\u5df1\u7684\u7f16\u53f7\u3002<\/p>\n<\/p>\n<p><h3>\u5341\u4e00\u3001\u90e8\u7f72\u548c\u53d1\u5e03<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u53d1\u5b8c\u6210\u540e\uff0c\u53ef\u80fd\u9700\u8981\u5c06Python\u811a\u672c\u90e8\u7f72\u5230\u670d\u52a1\u5668\u4e0a\u8fd0\u884c\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528\u865a\u62df\u73af\u5883<\/h4>\n<\/p>\n<p><p>\u4e3a\u4e86\u907f\u514d\u4e0d\u540c\u9879\u76ee\u4e4b\u95f4\u7684\u5e93\u51b2\u7a81\uff0c\u5efa\u8bae\u4f7f\u7528\u865a\u62df\u73af\u5883\u3002\u521b\u5efa\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code>python -m venv myenv<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6fc0\u6d3b\u865a\u62df\u73af\u5883\uff1a<\/p>\n<\/p>\n<p><pre><code>source myenv\/bin\/activate<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u865a\u62df\u73af\u5883\u4e2d\u5b89\u88c5\u9879\u76ee\u4f9d\u8d56\uff1a<\/p>\n<\/p>\n<p><pre><code>pip install -r requirements.txt<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u90e8\u7f72\u5230\u670d\u52a1\u5668<\/h4>\n<\/p>\n<p><p>\u5c06\u9879\u76ee\u6587\u4ef6\u4e0a\u4f20\u5230\u670d\u52a1\u5668\uff0c\u786e\u4fdd\u670d\u52a1\u5668\u4e0a\u5b89\u88c5\u4e86Python\u548c\u6240\u6709\u5fc5\u8981\u7684\u4f9d\u8d56\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fd0\u884c\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code>python your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>\u5341\u4e8c\u3001\u81ea\u52a8\u5316\u4efb\u52a1<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u53d1\u548c\u90e8\u7f72\u8fc7\u7a0b\u4e2d\uff0c\u81ea\u52a8\u5316\u4efb\u52a1\u53ef\u4ee5\u63d0\u9ad8\u6548\u7387\u3002\u53ef\u4ee5\u4f7f\u7528<code>cron<\/code>\u6765\u5b9a\u65f6\u8fd0\u884cPython\u811a\u672c\u3002<\/p>\n<\/p>\n<p><h4>1. \u5b89\u88c5cron<\/h4>\n<\/p>\n<p><p>\u5728Termux\u4e2d\u5b89\u88c5cron\uff1a<\/p>\n<\/p>\n<p><pre><code>pkg install cronie<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u542f\u52a8cron\u670d\u52a1\uff1a<\/p>\n<\/p>\n<p><pre><code>crond<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u914d\u7f6ecron\u4efb\u52a1<\/h4>\n<\/p>\n<p><p>\u7f16\u8f91cron\u4efb\u52a1\u5217\u8868\uff1a<\/p>\n<\/p>\n<p><pre><code>crontab -e<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\u6765\u6bcf\u5929\u51cc\u6668\u8fd0\u884c\u811a\u672c\uff1a<\/p>\n<\/p>\n<p><pre><code>0 0 * * * \/data\/data\/com.termux\/files\/usr\/bin\/python \/path\/to\/your_script.py<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u4fdd\u5b58\u5e76\u9000\u51fa\uff0ccron\u5c06\u4f1a\u5b9a\u65f6\u8fd0\u884c\u4f60\u7684\u811a\u672c\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4ee5\u4e0a\u6b65\u9aa4\uff0c\u4f60\u53ef\u4ee5\u5728Termux\u4e2d\u987a\u5229\u5b89\u88c5\u548c\u4f7f\u7528Python\u8fdb\u884c\u5f00\u53d1\u3002\u4e0d\u4ec5\u53ef\u4ee5\u5b9e\u73b0\u57fa\u672c\u7684\u5f00\u53d1\u9700\u6c42\uff0c\u8fd8\u53ef\u4ee5\u5229\u7528\u9ad8\u7ea7\u6280\u5de7\u548c\u5de5\u5177\u6765\u4f18\u5316\u548c\u7ba1\u7406\u9879\u76ee\u3002\u5e0c\u671b\u8fd9\u4e9b\u5185\u5bb9\u80fd\u5bf9\u4f60\u5728Termux\u4e2d\u4f7f\u7528Python\u6709\u6240\u5e2e\u52a9\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>Termux\u4e2d\u5982\u4f55\u5b89\u88c5Python\uff1f<\/strong><br \/>\u5728Termux\u4e2d\u5b89\u88c5Python\u975e\u5e38\u7b80\u5355\u3002\u9996\u5148\uff0c\u6253\u5f00Termux\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u901a\u8fc7\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u6765\u66f4\u65b0\u8f6f\u4ef6\u5305\u5217\u8868\uff1a<code>pkg update<\/code>\u3002\u63a5\u7740\uff0c\u5b89\u88c5Python\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4<code>pkg install python<\/code>\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u8f93\u5165<code>python<\/code>\u6216<code>python3<\/code>\u6765\u542f\u52a8Python\u89e3\u91ca\u5668\uff0c\u68c0\u67e5\u662f\u5426\u6210\u529f\u5b89\u88c5\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\u53ef\u4ee5\u4f7f\u7528\u6587\u672c\u7f16\u8f91\u5668\uff08\u5982vim\u6216nano\uff09\u6765\u521b\u5efa\u6587\u4ef6\uff0c\u4f8b\u5982\u8f93\u5165<code>nano script.py<\/code>\u6765\u521b\u5efa\u540d\u4e3a<code>script.py<\/code>\u7684\u6587\u4ef6\u3002\u5728\u6587\u4ef6\u4e2d\u7f16\u5199\u60a8\u7684Python\u4ee3\u7801\u540e\uff0c\u4fdd\u5b58\u5e76\u9000\u51fa\u7f16\u8f91\u5668\u3002\u7136\u540e\uff0c\u901a\u8fc7\u547d\u4ee4<code>python script.py<\/code>\u6216<code>python3 script.py<\/code>\u6765\u8fd0\u884c\u60a8\u7684\u811a\u672c\u3002<\/p>\n<p><strong>Termux\u5982\u4f55\u5904\u7406Python\u5e93\u7684\u5b89\u88c5\uff1f<\/strong><br \/>\u5728Termux\u4e2d\u5b89\u88c5Python\u5e93\u540c\u6837\u7b80\u5355\uff0c\u53ef\u4ee5\u4f7f\u7528<code>pip<\/code>\u5de5\u5177\u3002\u9996\u5148\uff0c\u786e\u4fdd\u60a8\u5df2\u7ecf\u5b89\u88c5\u4e86pip\uff08\u901a\u5e38Python\u4f1a\u81ea\u5e26pip\uff09\u3002\u4f7f\u7528\u547d\u4ee4<code>pip install package_name<\/code>\u6765\u5b89\u88c5\u6240\u9700\u7684\u5e93\uff0c\u4f8b\u5982<code>pip install requests<\/code>\u3002\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u60a8\u5c31\u53ef\u4ee5\u5728Python\u811a\u672c\u4e2d\u5bfc\u5165\u5e76\u4f7f\u7528\u8fd9\u4e9b\u5e93\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5f00\u5934\u6bb5\u843d\uff1a \u5728Termux\u4e2d\u4f7f\u7528Python\uff0c\u4e3b\u8981\u6b65\u9aa4\u5305\u62ec\u5b89\u88c5Termux\u3001\u5b89\u88c5Python\u3001\u914d\u7f6e\u73af\u5883\u3001\u5b89\u88c5\u6240 [&hellip;]","protected":false},"author":3,"featured_media":1155705,"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\/1155698"}],"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=1155698"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1155698\/revisions"}],"predecessor-version":[{"id":1155707,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1155698\/revisions\/1155707"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1155705"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1155698"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1155698"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1155698"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}