{"id":1129949,"date":"2025-01-08T20:34:15","date_gmt":"2025-01-08T12:34:15","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1129949.html"},"modified":"2025-01-08T20:34:18","modified_gmt":"2025-01-08T12:34:18","slug":"python%e5%a6%82%e4%bd%95%e6%89%93%e5%8c%85%e6%88%90%e6%89%8b%e6%9c%ba%e5%8f%af%e6%89%a7%e8%a1%8c%e6%96%87%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1129949.html","title":{"rendered":"python\u5982\u4f55\u6253\u5305\u6210\u624b\u673a\u53ef\u6267\u884c\u6587\u4ef6"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25100205\/93fe1ec1-3e1f-49ef-91c0-2035ccdbea40.webp\" alt=\"python\u5982\u4f55\u6253\u5305\u6210\u624b\u673a\u53ef\u6267\u884c\u6587\u4ef6\" \/><\/p>\n<p><p> <strong>Python\u5982\u4f55\u6253\u5305\u6210\u624b\u673a\u53ef\u6267\u884c\u6587\u4ef6\uff1a<\/strong> \u6253\u5305Python\u811a\u672c\u6210\u624b\u673a\u53ef\u6267\u884c\u6587\u4ef6\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u76ee\u6807\u64cd\u4f5c\u7cfb\u7edf\u3002<strong>\u4f7f\u7528Kivy\u6846\u67b6\u3001\u5229\u7528BeeWare\u5de5\u5177\u3001\u901a\u8fc7Pydroid 3\u5e94\u7528\u3001\u91c7\u7528SL4A\u5e93<\/strong>\u7b49\u662f\u5176\u4e2d\u8f83\u4e3a\u6d41\u884c\u7684\u65b9\u6cd5\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u4f7f\u7528Kivy\u6846\u67b6\u6765\u6253\u5305Python\u811a\u672c\u6210\u5b89\u5353\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001KIVY\u6846\u67b6<\/h3>\n<\/p>\n<p><p>Kivy\u662f\u4e00\u4e2a\u5f00\u6e90Python\u5e93\uff0c\u53ef\u4ee5\u7528\u6765\u5feb\u901f\u5f00\u53d1\u591a\u70b9\u89e6\u63a7\u5e94\u7528\u7a0b\u5e8f\u3002\u5b83\u4e0d\u4ec5\u53ef\u4ee5\u5728Windows\u3001Linux\u3001OS X\u7b49\u684c\u9762\u5e73\u53f0\u4e0a\u8fd0\u884c\uff0c\u8fd8\u652f\u6301\u5728iOS\u548cAndroid\u7b49\u79fb\u52a8\u5e73\u53f0\u4e0a\u8fd0\u884c\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b89\u88c5Kivy<\/h4>\n<\/p>\n<p><p>\u8981\u5f00\u59cb\u4f7f\u7528Kivy\uff0c\u9996\u5148\u9700\u8981\u5b89\u88c5\u8fd9\u4e2a\u6846\u67b6\u3002\u53ef\u4ee5\u901a\u8fc7pip\u8fdb\u884c\u5b89\u88c5\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install kivy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u6b64\u5916\uff0c\u8fd8\u9700\u8981\u5b89\u88c5\u4e00\u4e9b\u4f9d\u8d56\u9879\uff0c\u5982Cython\u548cPillow\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install cython pillow<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u521b\u5efaKivy\u5e94\u7528<\/h4>\n<\/p>\n<p><p>\u5728\u5b89\u88c5\u5b8cKivy\u4e4b\u540e\uff0c\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684Kivy\u5e94\u7528\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u57fa\u672c\u7684Kivy\u5e94\u7528\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from kivy.app import App<\/p>\n<p>from kivy.uix.label import Label<\/p>\n<p>class MyApp(App):<\/p>\n<p>    def build(self):<\/p>\n<p>        return Label(text=&quot;Hello, Kivy!&quot;)<\/p>\n<p>if __name__ == &quot;__m<a href=\"https:\/\/docs.pingcode.com\/blog\/59162.html\" target=\"_blank\">AI<\/a>n__&quot;:<\/p>\n<p>    MyApp().run()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>3\u3001\u4f7f\u7528Buildozer\u6253\u5305<\/h4>\n<\/p>\n<p><p>Buildozer\u662f\u4e00\u4e2a\u7b80\u5355\u7684\u5de5\u5177\uff0c\u53ef\u4ee5\u5c06Kivy\u5e94\u7528\u6253\u5305\u6210Android\u548ciOS\u7684\u53ef\u6267\u884c\u6587\u4ef6\u3002\u9996\u5148\uff0c\u5b89\u88c5Buildozer\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install buildozer<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u7136\u540e\uff0c\u521d\u59cb\u5316\u4e00\u4e2a\u65b0\u9879\u76ee\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">buildozer init<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u4f1a\u5728\u9879\u76ee\u76ee\u5f55\u4e0b\u751f\u6210\u4e00\u4e2a<code>buildozer.spec<\/code>\u6587\u4ef6\uff0c\u914d\u7f6e\u6587\u4ef6\u4e2d\u5305\u542b\u4e86\u6253\u5305\u5e94\u7528\u6240\u9700\u7684\u6240\u6709\u4fe1\u606f\u3002\u53ef\u4ee5\u6839\u636e\u9700\u8981\u4fee\u6539\u8fd9\u4e2a\u6587\u4ef6\uff0c\u6bd4\u5982\u8bbe\u7f6e\u5e94\u7528\u7684\u540d\u5b57\u3001\u7248\u672c\u53f7\u7b49\u3002<\/p>\n<\/p>\n<p><p>\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6765\u6253\u5305\u5e94\u7528\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">buildozer -v android debug<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u4e2a\u8fc7\u7a0b\u53ef\u80fd\u4f1a\u82b1\u8d39\u4e00\u4e9b\u65f6\u95f4\uff0c\u56e0\u4e3aBuildozer\u9700\u8981\u4e0b\u8f7d\u548c\u5b89\u88c5\u5f88\u591a\u4f9d\u8d56\u9879\u3002\u6253\u5305\u5b8c\u6210\u540e\uff0c\u53ef\u4ee5\u5728<code>bin<\/code>\u76ee\u5f55\u4e0b\u627e\u5230\u751f\u6210\u7684APK\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001BEEWARE\u5de5\u5177<\/h3>\n<\/p>\n<p><p>BeeWare\u662f\u4e00\u5957\u7528\u4e8e\u521b\u5efa\u8de8\u5e73\u53f0\u5e94\u7528\u7684\u5de5\u5177\u96c6\u3002\u5b83\u652f\u6301Windows\u3001macOS\u3001Linux\u3001iOS\u548cAndroid\u7b49\u591a\u4e2a\u5e73\u53f0\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b89\u88c5BeeWare<\/h4>\n<\/p>\n<p><p>\u4f7f\u7528pip\u5b89\u88c5BeeWare\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">pip install briefcase<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2\u3001\u521b\u5efaBeeWare\u5e94\u7528<\/h4>\n<\/p>\n<p><p>\u521b\u5efa\u4e00\u4e2a\u65b0\u7684BeeWare\u9879\u76ee\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">briefcase new<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u4f1a\u751f\u6210\u4e00\u4e2a\u57fa\u672c\u7684\u9879\u76ee\u7ed3\u6784\u3002\u53ef\u4ee5\u5728<code>src<\/code>\u76ee\u5f55\u4e0b\u627e\u5230Python\u6e90\u4ee3\u7801\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>3\u3001\u6253\u5305BeeWare\u5e94\u7528<\/h4>\n<\/p>\n<p><p>\u8981\u5c06\u5e94\u7528\u6253\u5305\u6210Android\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u9700\u8981\u5b89\u88c5Android SDK\u548cNDK\u3002\u7136\u540e\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u6253\u5305\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-bash\">briefcase create android<\/p>\n<p>briefcase build android<\/p>\n<p>briefcase run android<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8fd9\u5c06\u4f1a\u751f\u6210\u4e00\u4e2aAPK\u6587\u4ef6\uff0c\u53ef\u4ee5\u5b89\u88c5\u5230Android\u8bbe\u5907\u4e0a\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001PYDROID 3\u5e94\u7528<\/h3>\n<\/p>\n<p><p>Pydroid 3\u662f\u4e00\u4e2aAndroid\u5e94\u7528\uff0c\u53ef\u4ee5\u76f4\u63a5\u5728\u624b\u673a\u4e0a\u8fd0\u884cPython\u4ee3\u7801\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b89\u88c5Pydroid 3<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4eceGoogle Play Store\u4e0b\u8f7d\u5e76\u5b89\u88c5Pydroid 3\u5e94\u7528\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u8fd0\u884cPython\u4ee3\u7801<\/h4>\n<\/p>\n<p><p>\u5728Pydroid 3\u5e94\u7528\u4e2d\uff0c\u53ef\u4ee5\u76f4\u63a5\u7f16\u5199\u548c\u8fd0\u884cPython\u4ee3\u7801\u3002Pydroid 3\u8fd8\u652f\u6301\u8bb8\u591a\u5e38\u7528\u7684Python\u5e93\uff0c\u5982NumPy\u3001Pandas\u7b49\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001SL4A\u5e93<\/h3>\n<\/p>\n<p><p>SL4A\uff08Scripting Layer for Android\uff09\u662f\u4e00\u4e2a\u53ef\u4ee5\u5728Android\u8bbe\u5907\u4e0a\u8fd0\u884c\u811a\u672c\u7684\u5de5\u5177\u3002<\/p>\n<\/p>\n<p><h4>1\u3001\u5b89\u88c5SL4A<\/h4>\n<\/p>\n<p><p>\u53ef\u4ee5\u4eceSL4A\u5b98\u7f51\u6216\u5176\u4ed6\u5e94\u7528\u5e02\u573a\u4e0b\u8f7d\u5e76\u5b89\u88c5SL4A\u5e94\u7528\u3002<\/p>\n<\/p>\n<p><h4>2\u3001\u8fd0\u884cPython\u811a\u672c<\/h4>\n<\/p>\n<p><p>\u5728SL4A\u4e2d\uff0c\u53ef\u4ee5\u76f4\u63a5\u8fd0\u884cPython\u811a\u672c\u3002SL4A\u8fd8\u63d0\u4f9b\u4e86\u8bb8\u591aAPI\uff0c\u53ef\u4ee5\u4e0eAndroid\u7cfb\u7edf\u8fdb\u884c\u4ea4\u4e92\uff0c\u5982\u8bbf\u95ee\u4f20\u611f\u5668\u3001\u6444\u50cf\u5934\u7b49\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u5176\u5b83\u5de5\u5177\u548c\u65b9\u6cd5<\/h3>\n<\/p>\n<p><p>\u9664\u4e86\u4e0a\u8ff0\u65b9\u6cd5\uff0c\u8fd8\u6709\u4e00\u4e9b\u5176\u4ed6\u5de5\u5177\u548c\u65b9\u6cd5\u53ef\u4ee5\u5c06Python\u811a\u672c\u6253\u5305\u6210\u624b\u673a\u53ef\u6267\u884c\u6587\u4ef6\u3002<\/p>\n<\/p>\n<p><h4>1\u3001Pyqtdeploy<\/h4>\n<\/p>\n<p><p>Pyqtdeploy\u662f\u4e00\u4e2a\u5c06PyQt\u5e94\u7528\u6253\u5305\u6210\u72ec\u7acb\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5de5\u5177\u3002\u5b83\u652f\u6301Windows\u3001macOS\u3001Linux\u3001iOS\u548cAndroid\u7b49\u591a\u4e2a\u5e73\u53f0\u3002<\/p>\n<\/p>\n<p><h4>2\u3001PyInstaller<\/h4>\n<\/p>\n<p><p>PyInstaller\u662f\u4e00\u4e2a\u5c06Python\u811a\u672c\u6253\u5305\u6210\u72ec\u7acb\u53ef\u6267\u884c\u6587\u4ef6\u7684\u5de5\u5177\u3002\u867d\u7136PyInstaller\u4e3b\u8981\u7528\u4e8e\u684c\u9762\u5e94\u7528\uff0c\u4f46\u4e5f\u6709\u4e00\u4e9b\u65b9\u6cd5\u53ef\u4ee5\u5c06\u5176\u7528\u4e8e\u79fb\u52a8\u5e73\u53f0\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3<\/h3>\n<\/p>\n<p><p>\u5c06Python\u811a\u672c\u6253\u5305\u6210\u624b\u673a\u53ef\u6267\u884c\u6587\u4ef6\u7684\u65b9\u6cd5\u6709\u5f88\u591a\uff0c\u5177\u4f53\u9009\u62e9\u54ea\u79cd\u65b9\u6cd5\u53d6\u51b3\u4e8e\u76ee\u6807\u64cd\u4f5c\u7cfb\u7edf\u548c\u5e94\u7528\u7684\u5177\u4f53\u9700\u6c42\u3002<strong>Kivy\u6846\u67b6\u3001BeeWare\u5de5\u5177\u3001Pydroid 3\u5e94\u7528\u3001SL4A\u5e93<\/strong>\u7b49\u662f\u5176\u4e2d\u8f83\u4e3a\u6d41\u884c\u7684\u65b9\u6cd5\u3002\u901a\u8fc7\u8fd9\u4e9b\u5de5\u5177\u548c\u65b9\u6cd5\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u5c06Python\u811a\u672c\u8f6c\u6362\u6210\u624b\u673a\u5e94\u7528\uff0c\u6ee1\u8db3\u5404\u79cd\u5f00\u53d1\u9700\u6c42\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5c06Python\u9879\u76ee\u6253\u5305\u6210\u9002\u7528\u4e8eAndroid\u624b\u673a\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff1f<\/strong><br \/>\u8981\u5c06Python\u9879\u76ee\u6253\u5305\u6210Android\u624b\u673a\u7684\u53ef\u6267\u884c\u6587\u4ef6\uff0c\u53ef\u4ee5\u4f7f\u7528\u5de5\u5177\u5982Kivy\u6216BeeWare\u3002Kivy\u662f\u4e00\u4e2a\u652f\u6301\u591a\u79cd\u5e73\u53f0\u7684Python\u6846\u67b6\uff0c\u80fd\u591f\u521b\u5efa\u8de8\u5e73\u53f0\u7684\u5e94\u7528\u3002BeeWare\u540c\u6837\u63d0\u4f9b\u4e86\u5c06Python\u5e94\u7528\u6253\u5305\u4e3aAndroid APK\u7684\u529f\u80fd\u3002\u60a8\u9700\u8981\u6309\u7167\u76f8\u5173\u6587\u6863\u4e2d\u7684\u6307\u5bfc\u8bbe\u7f6e\u73af\u5883\uff0c\u5e76\u4f7f\u7528\u5de5\u5177\u751f\u6210APK\u6587\u4ef6\u3002<\/p>\n<p><strong>\u53ef\u4ee5\u4f7f\u7528\u54ea\u4e9b\u5de5\u5177\u5c06Python\u5e94\u7528\u6253\u5305\u6210iOS\u53ef\u6267\u884c\u6587\u4ef6\uff1f<\/strong><br \/>\u5bf9\u4e8eiOS\u5e73\u53f0\uff0c\u53ef\u4ee5\u8003\u8651\u4f7f\u7528Kivy\u6216BeeWare\u3002Kivy\u5728iOS\u4e0a\u53ef\u4ee5\u901a\u8fc7Xcode\u8fdb\u884c\u6253\u5305\uff0c\u800cBeeWare\u63d0\u4f9b\u4e86\u4e00\u4e2a\u66f4\u4e3a\u7b80\u5316\u7684\u8fc7\u7a0b\uff0c\u5141\u8bb8\u5f00\u53d1\u8005\u521b\u5efaiOS\u5e94\u7528\u3002\u8bf7\u786e\u4fdd\u60a8\u6709\u9002\u5f53\u7684Apple\u5f00\u53d1\u8005\u8d26\u6237\u548cXcode\u73af\u5883\uff0c\u4ee5\u4fbf\u987a\u5229\u8fdb\u884c\u6253\u5305\u3002<\/p>\n<p><strong>\u6253\u5305Python\u7a0b\u5e8f\u65f6\uff0c\u5982\u4f55\u5904\u7406\u4f9d\u8d56\u5e93\u7684\u95ee\u9898\uff1f<\/strong><br \/>\u5728\u6253\u5305Python\u7a0b\u5e8f\u65f6\uff0c\u786e\u4fdd\u6240\u6709\u4f9d\u8d56\u5e93\u90fd\u5df2\u5b89\u88c5\u5e76\u6b63\u786e\u914d\u7f6e\u975e\u5e38\u91cd\u8981\u3002\u4f7f\u7528pip freeze\u547d\u4ee4\u53ef\u4ee5\u5217\u51fa\u6240\u6709\u4f9d\u8d56\u9879\uff0c\u5e76\u5c06\u5176\u5b58\u50a8\u5728requirements.txt\u6587\u4ef6\u4e2d\u3002\u6253\u5305\u5de5\u5177\u5982PyInstaller\u3001cx_Freeze\u6216PyOxidizer\u901a\u5e38\u4f1a\u81ea\u52a8\u5904\u7406\u4f9d\u8d56\u9879\uff0c\u4f46\u5efa\u8bae\u5728\u6253\u5305\u524d\u8fdb\u884c\u6d4b\u8bd5\uff0c\u4ee5\u786e\u4fdd\u6240\u6709\u529f\u80fd\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"Python\u5982\u4f55\u6253\u5305\u6210\u624b\u673a\u53ef\u6267\u884c\u6587\u4ef6\uff1a \u6253\u5305Python\u811a\u672c\u6210\u624b\u673a\u53ef\u6267\u884c\u6587\u4ef6\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5177\u4f53\u53d6\u51b3\u4e8e\u76ee\u6807\u64cd\u4f5c\u7cfb [&hellip;]","protected":false},"author":3,"featured_media":1129956,"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\/1129949"}],"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=1129949"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1129949\/revisions"}],"predecessor-version":[{"id":1129960,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1129949\/revisions\/1129960"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1129956"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1129949"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1129949"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1129949"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}