We are working on an S60 version and this platform has a nice Python API.
我们正在开发S60版本,这个平台有一个很好的Python API。
However, there is nothing official about Python on Android, but since Jython exists, is there a way to let the snake and the robot work together?
但是,在Android上没有关于Python的官方说法,但是既然Jython存在,有没有办法让蛇和机器人一起工作?
25 个解决方案
#1
759
One way is to use Kivy:
一种方法是使用Kivy:
Open source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps.
开放源码Python库,用于快速开发利用创新用户界面的应用程序,如多点触摸应用程序。
Kivy runs on Linux, Windows, OS X, Android and iOS. You can run the same [python] code on all supported platforms.
Kivy在Linux、Windows、OS X、Android和iOS上运行。您可以在所有支持的平台上运行相同的[python]代码。
Kivy展示应用程序
#2
292
There is also the new Android Scripting Environment (ASE/SL4A) project. It looks awesome, and it has some integration with native Android components.
还有一个新的Android脚本环境(ASE/SL4A)项目。它看起来很棒,而且它与本地的Android组件有一些集成。
Note: no longer under "active development", but some forks may be.
注意:不再处于“积极发展”之下,但可能有一些福克斯。
#3
175
是的!
An example via Matt Cutts via SL4A -- "here’s a barcode scanner written in six lines of Python code:
一个通过SL4A的Matt Cutts的例子——“这是一个用六行Python代码编写的条码扫描器:
import android
droid = android.Android()
code = droid.scanBarcode()
isbn = int(code['result']['SCAN_RESULT'])
url = "http://books.google.com?q=%d" % isbn
droid.startActivity('android.intent.action.VIEW', url)
#5
68
"The Pygame Subset for Android is a port of a subset of Pygame functionality to the Android platform. The goal of the project is to allow the creation of Android-specific games, and to ease the porting of games from PC-like platforms to Android."
Android的Pygame子集是Android平台Pygame功能的一个子集。该项目的目标是允许创建特定于Android的游戏,并将游戏从pc平台移植到Android平台上。
The examples include a complete game packaged in an APK, which is pretty interesting.
例子包括一个完整的游戏包装在APK,这是相当有趣的。
#6
61
I've posted instructions and a patch for cross compiling Python 2.7.2 for Android, you can get it at my blog here: http://mdqinc.com/blog/2011/09/cross-compiling-python-for-android/
我已经发布了指令和一个补丁,用于为Android编译Python 2.7.2,你可以在我的博客上找到它:http://mdqinc.com/blog/2011/09/cross- python/android/。
EDIT: I've open sourced Ignifuga, my 2D Game Engine, it's Python/SDL based and it cross compiles for Android. Even if you don't use it for games, you might get useful ideas from the code and the builder utility (named Schafer, after Tim...you know who).
编辑:我有开源的引擎,我的2D游戏引擎,它是基于Python/SDL的,它是为Android编译的。即使你没有在游戏中使用它,你也可以从代码和生成器工具中得到有用的想法(命名为Schafer,在Tim之后……)你知道是谁)。
#7
53
SL4A
Scripting Layer for Android does what you want. You can easily install it directly onto your device from their site, and do not need root.
Android的脚本层可以做你想做的事情。你可以很容易地从他们的网站直接安装到你的设备上,而且不需要root用户。
It supports a range of languages; Python is the most mature. By default, it uses Python 2.6, but there is a 3.2 port you can use instead. I have used that port for all kinds of things on a Galaxy S2 and it worked fine.
它支持多种语言;Python是最成熟的。默认情况下,它使用Python 2.6,但是您可以使用一个3.2端口。我用过这个端口来处理Galaxy S2上的各种东西,效果很好。
API
SL4A provides a port of their android
library for each supported language. The library provides an interface to the underlying Android API through a single Android
object.
SL4A为每个支持的语言提供了他们的android库的端口。该库通过一个单一的Android对象为底层Android API提供了一个接口。
import android
droid = android.Android()
# example using the text to speech facade
droid.ttsSpeak('hello world')
Each language has pretty much the same API. You can even use the JavaScript API inside webviews.
每种语言的API都差不多。您甚至可以在webviews内使用JavaScript API。
var droid = new Android();
droid.ttsSpeak('hello from js');
User Interfaces
For user interfaces, you have three options:
对于用户界面,您有三个选项:
- You can easily use the generic, native dialogues and menus through the API. This is good for confirmation dialogues and other basic user inputs.
- 您可以通过API轻松地使用通用的、本机的对话和菜单。这有利于确认对话和其他基本用户输入。
- You can also open a webview from inside a Python script, then use HTML5 for the user interface. When you use webviews from Python, you can pass messages back and forth, between the webview and the Python process that spawned it. The UI will not be native, but it is still a good option to have.
- 您还可以从Python脚本中打开webview,然后使用HTML5作为用户界面。当您使用Python的webviews时,您可以在webview和派生它的Python进程之间来回传递消息。UI不是本地的,但它仍然是一个不错的选择。
- There is some support for native Android user interfaces, but I am not sure how well it works; I just haven't ever used it.
- 对原生Android用户界面有一些支持,但我不确定它的效果如何;我只是从来没用过。
You can mix options, so you can have a webview for the main interface, and still use native dialogues.
您可以混合选项,因此可以为主界面设置webview,并且仍然使用本机对话。
QPython
There is a third party project named QPython. It builds on SL4A, and throws in some other useful stuff.
还有一个名为QPython的第三方项目。它建立在SL4A上,并抛出一些其他有用的东西。
QPython gives you a nicer UI to manage your installation, and includes a little, touchscreen code editor, a Python shell, and a PIP shell for package management. They also have a Python 3 port. Both versions are available from the Play Store, free of charge. QPython also bundles libraries from a bunch of Python on Android projects, including Kivy, so it is not just SL4A.
QPython为您提供了一个更好的UI来管理您的安装,并包括一个小的触摸屏代码编辑器、一个Python shell和一个用于包管理的PIP shell。他们还有一个Python 3端口。两个版本都可以从游戏商店免费下载。QPython还在Android项目(包括Kivy)上捆绑了大量Python库,所以它不仅仅是SL4A。
Note that QPython still develop their fork of SL4A (though, not much to be honest). The main SL4A project itself is pretty much dead.
请注意,QPython仍然开发他们的SL4A的分支(尽管,说实话)。主要的SL4A项目本身已经死了。
- SL4A Project (now on GitHub): https://github.com/damonkohler/sl4a
- SL4A项目(现在在GitHub上):https://github.com/damonkohler/sl4a。
- SL4A Python 3 Port: https://code.google.com/p/python-for-android/wiki/Python3
- SL4A Python3端口:https://code.google.com/p/pythonforandroid/wiki/python3。
- QPython Project: http://qpython.com
- QPython项目:http://qpython.com
#8
52
As a Python lover and Android programmer, I am sad to say this is not really a good way to go. There are two problems.
作为一个Python爱好者和Android程序员,我很遗憾地说,这并不是一个好方法。有两个问题。
One problem is that there is a lot more than just a programming language to the Android development tools. A lot of the Android graphics involve XML files to configure the display, similar to HTML. The built-in java objects are really integrated with this XML layout, and it's a lot easier than writing your own code to go from logic to bitmap.
一个问题是,Android开发工具不仅仅是一种编程语言。很多Android图形都涉及到XML文件来配置显示,类似于HTML。内置的java对象实际上与XML布局集成在一起,这比编写自己的代码从逻辑到位图要容易得多。
The other problem is that the G1 (and probably other Android devices for the near future) are really not that fast. 200 MHz processors, and RAM is very limited. Even in Java you have to do a decent amount of rewriting-to-avoid-more-object-creation if you want to make your app perfectly smooth. Python is going to be too slow for a while still on mobile devices.
另一个问题是G1(以及可能在不久的将来使用的其他Android设备)真的没有那么快。200 MHz处理器,RAM非常有限。即使是在Java中,如果你想让你的应用程序完美的平滑,你也需要做大量的重新编写——避免更多的对象创建。在移动设备上,Python的速度将会太慢。
#9
30
Not at the moment and you would be lucky to get Jython to work soon. If you're planning to start your development now you would be better off with just sticking to Java for now on.
现在还没有,你很快就能让Jython工作了。如果你正打算开始你的开发,你最好现在就坚持用Java。
#10
26
Using SL4A (which has already been mentioned by itself in other answers) you can run a full-blown web2py instance (other python web frameworks are likely candidates as well). SL4A doesn't allow you to do native UI components (buttons, scroll bars, and the like), but it does support WebViews. A WebView is basically nothing more than a striped down web browser pointed at a fixed address. I believe the native Gmail app uses a WebView instead of going the regular widget route.
使用SL4A(已经在其他答案中已经提到过),您可以运行一个成熟的web2py实例(其他python web框架也可能是候选的)。SL4A不允许您执行本机UI组件(按钮、滚动条等),但它支持WebViews。WebView基本上就是一个带条纹的web浏览器指向一个固定的地址。我相信本地Gmail应用程序使用的是WebView而不是常规的小部件路由。
This route would have some interesting features:
这条路线会有一些有趣的特点:
- In the case of most python web frameworks, you could actually develop and test without using an android device or android emulator.
- 在大多数python web框架的情况下,您实际上可以在不使用android设备或android模拟器的情况下开发和测试。
- Whatever Python code you end up writing for the phone could also be put on a public webserver with very little (if any) modification.
- 不管你最后为手机写的是什么Python代码,都可以放在一个非常小(如果有的话)的公共网络服务器上。
- You could take advantage of all of the crazy web stuff out there: query, HTML5, CSS3, etc.
- 你可以利用所有疯狂的网络内容:查询、HTML5、CSS3等等。
#11
25
Kivy
I want to post this as an extension of what @JohnMudd has already answered (but please bear with me as English isn't my first language)
我想把这个作为@JohnMudd已经回答的扩展(但是请容忍我,因为英语不是我的第一语言)
It has been years since then, and Kivy has evolved to v1.9-dev. The biggest selling point of Kivy, in my opinion, is its cross-platform compatibility. You can code and test under your local environment (Windows/*nix etc.), you can also build, debug and package your app to run on your Android/iOS/Mac/Windows devices.
从那时起已经有好几年了,Kivy已经发展到v1.9-dev。在我看来,Kivy最大的卖点就是它的跨平台兼容性。您可以在您的本地环境(Windows/*nix等)下进行编码和测试,您还可以在您的Android/iOS/Mac/Windows设备上构建、调试和打包您的应用程序。
With Kivy's own KV language, you can code and build the GUI interface easily (it's just like Java XML, but rather than TextView etc., KV has its own ui.widgets
for the similar translation), which is in my opinion quite easy to adopt.
通过Kivy自己的KV语言,您可以轻松地编写和构建GUI界面(它就像Java XML,而不是TextView等等,KV有它自己的ui)。小部件的类似翻译),这是我认为很容易采用的。
Currently Buildozer and python-for-android are the most recommended tools to build/package your apps. I have tried them both and can firmly say that they make building Android apps with Python a breeze. Users who feel comfortable in their console/terminal/command prompt should have no problems using them, and their guides are well documented, too.
目前,Buildozer和python-for-android是构建/打包应用程序的最推荐工具。我已经尝试过这两种方法,并且可以肯定地说,他们用Python轻松构建Android应用程序。在控制台/终端/命令提示符中感到舒适的用户使用它们时应该没有问题,而且它们的向导也有良好的文档记录。
Furthermore, iOS is another big selling point of Kivy, provided that you can use the same code base with little changes required to test-run on your iOS device, via kivy-ios Homebrew tools, although Xcode is required for the build before running on their devices (AFAIK the iOS Simulator in Xcode currently doesn't work for the x86-architecture build). There are also some dependency issues which must be manually compiled and fiddled around with in Xcode to have a successful build, but they wouldn't be too difficult to resolve and people in Kivy Google Group are really helpful too.
此外,iOS是Kivy的另一大卖点,提供,您可以使用相同的代码基的小变化要求也是你的iOS设备上,通过kivy-ios自酿酒工具,尽管Xcode需要构建在他们的设备上运行(AFAIK iOS模拟器在Xcode中目前对x86架构构建不起作用)。还有一些依赖性问题,必须手动编译,并在Xcode中进行处理,以获得成功的构建,但是它们不会太难解决,Kivy谷歌组的人员也很有帮助。
With all being said, users with good Python knowledge should have no problem picking up the basics in weeks (if not days) to build some simple apps.
尽管如此,拥有良好的Python知识的用户应该在几个星期(如果不是几天)的基础上找到一些简单的应用程序。
Also worth mentioning is that you can bundle (build recipes) your Python modules with the build so users can really make use of many existing libraries Python bring us, like Requests & PIL etc. through Kivy's extension support.
值得一提的是,您可以将您的Python模块打包(构建菜谱),这样用户就可以通过Kivy的扩展支持,真正地利用许多现有的库Python带给我们,比如请求和PIL。
Sometimes your application requires functionality that is beyond the scope of what Kivy can deliver. In those cases, it is necessary to resort to external software libraries. Given the richness of the Python ecosystem, there is already a lot of software libraries that you can simply import and use right away.
有时,您的应用程序需要的功能超出了Kivy所能交付的范围。在这种情况下,有必要求助于外部软件库。考虑到Python生态系统的丰富程度,已经有很多软件库可以直接导入和使用。
The last but not the least, if you are going to use Kivy for more serious/commercial projects, you may find existing modules not satisfactory. There are some workable solutions though, with the "work in progress" of pyjnius for Android, and pyobjus. Users can now access Java/Objective-C classes through those modules to control some of the native APIs.
最后但不是最不重要的,如果你打算用Kivy来做更严肃的/商业项目,你可能会发现现有的模块并不令人满意。不过,有一些可行的解决方案,比如Android的pyjnius的“工作进展”和pyobjus。用户现在可以通过这些模块访问Java/Objective-C类来控制一些本地api。
My experience in Kivy is that it will find its best fit with seasoned Python programmers and some serious programmers who want rapid development or simple code base maintenance. It runs well on multiple platforms, albeit not really with the native feeling.
我在Kivy的经验是,它将发现它最适合于经验丰富的Python程序员和一些需要快速开发或简单代码基础维护的严肃程序员。它在多个平台上运行良好,尽管不是真正的本地感觉。
I do hope some Python app programmers find this information useful and start taking a look at Kivy. It can only get better (with more support and as libraries/modules get ported) if there is great interest from the community.
我确实希望一些Python应用程序的程序员觉得这些信息有用,并开始看一看Kivy。如果社区有很大的兴趣,它只会变得更好(有更多的支持和库/模块的移植)。
P.S. I have no relationship with Kivy whatsoever, I'm merely a programmer who really likes the idea of bringing Python coding fun to mobile/cross-platform development.
我和Kivy之间没有任何关系,我只是一个真正喜欢把Python编程的乐趣带到移动/跨平台开发的程序员。
#12
18
I use the QPython application. It has an editor, a console, and you can run your Python programs with it. The application is free, and the link is http://qpython.com/.
我使用了QPython应用程序。它有一个编辑器、一个控制台,您可以使用它运行您的Python程序。该应用程序是免费的,链接是http://qpython.com/。
#13
17
From the Python for android site:
android站点的Python:
Python for android is a project to create your own Python distribution including the modules you want, and create an apk including python, libs, and your application.
android的Python是一个创建您自己的Python发行版的项目,包括您想要的模块,并创建一个apk,包括Python、libs和您的应用程序。
#14
14
Yet another attempt: https://code.google.com/p/android-python27/
另一个尝试:https://code.google.com/p/android-python27/
This one embed directly the Python interpretter in your app apk.
这一个直接嵌入你的应用程序apk中的Python解释器。
#15
12
There are several ways to use Python on Android.
有几种方法可以在Android上使用Python。
BeeWare is a collection of tools for building native user interfaces
BeeWare是一个用于构建本地用户界面的工具集。
Chaquopy is a plugin for Android Studio's Gradle-based build system.
Chaquopy是Android Studio基于等级的构建系统的插件。
Kivy is a cross-platform OpenGL-based user interface toolkit.
Kivy是一个基于opengl的用户界面工具包。
pyqtdeploy is a tool for deploying PyQt applications.
pyqtdeploy是部署PyQt应用程序的工具。
QPython is an on-device script engine and development environment.
QPython是一个设备上的脚本引擎和开发环境。
SL4A (Scripting Layer for Android), originally named ASE (Android Scripting Environment), is a set of "facades" which expose a greatly-simplified subset of the Android API.
SL4A (Android的脚本层),最初命名为ASE (Android脚本环境),是一组“facades”,它公开了Android API的一个非常简化的子集。
PySide (the Python binding for the Qt toolkit) has some preliminary support for Android.
PySide(用于Qt工具包的Python绑定)对Android有一些初步的支持。
Although Android's primary programming language is Java, there is no known port of Jython to the platform. Android support in BeeWare is achieved using VOC, a tool that compiles Python source code to Java class files. This allows Python code to be executed as a native binary on the JVM. https://wiki.python.org/moin/Android
虽然Android的主要编程语言是Java,但是没有已知的Jython端口。在BeeWare中,Android的支持是通过使用VOC来实现的,VOC是将Python源代码编译成Java类文件的工具。这允许将Python代码作为本地二进制代码在JVM上执行。https://wiki.python.org/moin/Android
#16
#17
7
There's also python-on-a-chip possibly running mosync: google group
还有python-on-a-chip可能运行的mosync:谷歌组。
#18
7
Another option if you are looking for 3.4.2 or 3.5.1 is this archive on GitHub.
如果您要查找3.4.2或3.5.1,则另一个选项是GitHub上的存档。
Python3-Android 3.4.2 or Python3-Android 3.5.1
Python3-Android 3.4.2或Python3-Android 3.5.1。
It currently supports Python 3.4.2 or 3.5.1 and the 10d version of the NDK. It can also support 3.3 and 9c, 11c and 12
它目前支持Python 3.4.2或3.5.1和NDK的10d版本。它还可以支持3.3和9c、11c和12。
It's nice in that you simply download it, run make and you get the .so or the .a
它很好,你只要下载它,运行make,你就能得到so或a。
I currently use this to run raw Python on android devices. With a couple modifications to the build files you can also make x86 and armeabi 64 bit
我现在使用它在android设备上运行原始的Python。通过对构建文件进行一些修改,您还可以使x86和armeabi 64位。
#19
6
Didn't see this posted here, but you can do it with Pyside and Qt now that Qt works on Android thanks to Necessitas.
在这里没有看到这个帖子,但是你可以用Pyside和Qt来做,因为Qt在Android上的工作是需要的。
It seems like quite a kludge at the moment but could be a viable route eventually...
目前看来,这是一种相当笨拙的操作,但最终可能是可行的。
http://qt-project.org/wiki/PySide_for_Android_guide
http://qt-project.org/wiki/PySide_for_Android_guide
#20
6
You can use Termux application:
您可以使用Termux应用程序:
Note that apt install python install python 3. for python 2 you shoud call apt install python2.
注意,apt安装python安装python 3。对于python2,您应该调用apt安装python2。
Some demos here: https://www.youtube.com/watch?v=fqqsl72mASE
一些演示:https://www.youtube.com/watch?v=fqqsl72mASE
And also the github page: https://github.com/termux
还有github页面:https://github.com/termux。
#21
5
You can use QPython:
您可以使用QPython:
It has a Python Console, Editor, as well as Package Management / Installers
它有一个Python控制台、编辑器以及包管理/安装程序。
http://qpython.com/
It's an open source project with both Python 2 and Python 3 implementations. You can download the source and the Android .apk files directly from github.
它是一个使用Python 2和Python 3实现的开放源码项目。您可以直接从github下载源代码和Android .apk文件。
QPython 2: https://github.com/qpython-android/qpython/releases
QPython 2:https://github.com/qpython-android/qpython/releases
QPython 3: https://github.com/qpython-android/qpython3/releases
QPython 3:https://github.com/qpython-android/qpython3/releases
#22
5
There is an app called QPython3 in playstore which can be used for both editing and running python script.
在playstore中有一个名为QPython3的应用程序,可以用于编辑和运行python脚本。
Playstore链接
Another app called Termux in which you can install python using command
另一种名为Termux的应用程序可以使用命令来安装python。
pkg install python
Playstore链接
#23
3
One more option seems to be pyqtdeploy which citing the docs is:
另一个选项似乎是pyqtdeploy,引用文档的是:
a tool that, in conjunction with other tools provided with Qt, enables the deployment of PyQt4 and PyQt5 applications written with Python v2.7 or Python v3.3 or later. It supports deployment to desktop platforms (Linux, Windows and OS X) and to mobile platforms (iOS and Android).
与Qt提供的其他工具结合使用的工具,可以部署PyQt4和PyQt5应用程序,使用Python v2.7或Python v3.3或更高版本编写。它支持部署到桌面平台(Linux、Windows和OS X)和移动平台(iOS和Android)。
According to Deploying PyQt5 application to Android via pyqtdeploy and Qt5 it is actively developed, although it is difficult to find examples of working Android apps or tutorial on how to cross-compile all the required libraries to Android. It is an interesting project to keep in mind though!
通过pyqtdeploy和Qt5将PyQt5应用程序部署到Android上,它是积极开发的,尽管很难找到运行Android应用程序的例子,也很难找到如何将所有必需的库编译成Android的教程。不过,这是一个很有趣的项目。
#24
1
Chaquopy
Chaquopy is a plugin for Android Studio's Gradle-based build system. It focuses on close integration with the standard Android development tools.
Chaquopy是Android Studio基于等级的构建系统的插件。它专注于与标准的Android开发工具的紧密集成。
-
It provides complete APIs to call Java from Python or Python from Java, allowing the developer to use whichever language is best for each component of their app.
它提供了完整的api,可以从Python或Python中调用Java,允许开发人员在应用程序的每个组件中使用最适合的语言。
-
It can automatically download PyPI packages and build them into an app, including selected native packages such as NumPy.
它可以自动下载PyPI包并将其构建到一个应用程序中,包括选择的本地包(如NumPy)。
-
It enables full access to all Android APIs from Python, including the native user interface toolkit (example pure-Python activity).
它允许从Python中完全访问所有Android api,包括本地用户界面工具箱(例如pure-Python活动)。
This is a commercial product, but it's free for open-source use and will always remain that way.
这是一个商业产品,但它是免费的开源使用并且将一直保持这种方式。
(I am the creator of this product.)
(我是这个产品的创造者。)
#25
0
Take a look at BeeWare. At the moment of answering this question it is still in early development. It's aim is to be able to create native apps with Python for all supported operating systems, including Android.
看一看BeeWare。在回答这个问题的时候,它还处于早期发展阶段。它的目标是能够用Python为所有支持的操作系统(包括Android)创建本地应用程序。
#1
759
One way is to use Kivy:
一种方法是使用Kivy:
Open source Python library for rapid development of applications that make use of innovative user interfaces, such as multi-touch apps.
开放源码Python库,用于快速开发利用创新用户界面的应用程序,如多点触摸应用程序。
Kivy runs on Linux, Windows, OS X, Android and iOS. You can run the same [python] code on all supported platforms.
Kivy在Linux、Windows、OS X、Android和iOS上运行。您可以在所有支持的平台上运行相同的[python]代码。
Kivy展示应用程序
#2
292
There is also the new Android Scripting Environment (ASE/SL4A) project. It looks awesome, and it has some integration with native Android components.
还有一个新的Android脚本环境(ASE/SL4A)项目。它看起来很棒,而且它与本地的Android组件有一些集成。
Note: no longer under "active development", but some forks may be.
注意:不再处于“积极发展”之下,但可能有一些福克斯。
#3
175
是的!
An example via Matt Cutts via SL4A -- "here’s a barcode scanner written in six lines of Python code:
一个通过SL4A的Matt Cutts的例子——“这是一个用六行Python代码编写的条码扫描器:
import android
droid = android.Android()
code = droid.scanBarcode()
isbn = int(code['result']['SCAN_RESULT'])
url = "http://books.google.com?q=%d" % isbn
droid.startActivity('android.intent.action.VIEW', url)
#4
#5
68
"The Pygame Subset for Android is a port of a subset of Pygame functionality to the Android platform. The goal of the project is to allow the creation of Android-specific games, and to ease the porting of games from PC-like platforms to Android."
Android的Pygame子集是Android平台Pygame功能的一个子集。该项目的目标是允许创建特定于Android的游戏,并将游戏从pc平台移植到Android平台上。
The examples include a complete game packaged in an APK, which is pretty interesting.
例子包括一个完整的游戏包装在APK,这是相当有趣的。
#6
61
I've posted instructions and a patch for cross compiling Python 2.7.2 for Android, you can get it at my blog here: http://mdqinc.com/blog/2011/09/cross-compiling-python-for-android/
我已经发布了指令和一个补丁,用于为Android编译Python 2.7.2,你可以在我的博客上找到它:http://mdqinc.com/blog/2011/09/cross- python/android/。
EDIT: I've open sourced Ignifuga, my 2D Game Engine, it's Python/SDL based and it cross compiles for Android. Even if you don't use it for games, you might get useful ideas from the code and the builder utility (named Schafer, after Tim...you know who).
编辑:我有开源的引擎,我的2D游戏引擎,它是基于Python/SDL的,它是为Android编译的。即使你没有在游戏中使用它,你也可以从代码和生成器工具中得到有用的想法(命名为Schafer,在Tim之后……)你知道是谁)。
#7
53
SL4A
Scripting Layer for Android does what you want. You can easily install it directly onto your device from their site, and do not need root.
Android的脚本层可以做你想做的事情。你可以很容易地从他们的网站直接安装到你的设备上,而且不需要root用户。
It supports a range of languages; Python is the most mature. By default, it uses Python 2.6, but there is a 3.2 port you can use instead. I have used that port for all kinds of things on a Galaxy S2 and it worked fine.
它支持多种语言;Python是最成熟的。默认情况下,它使用Python 2.6,但是您可以使用一个3.2端口。我用过这个端口来处理Galaxy S2上的各种东西,效果很好。
API
SL4A provides a port of their android
library for each supported language. The library provides an interface to the underlying Android API through a single Android
object.
SL4A为每个支持的语言提供了他们的android库的端口。该库通过一个单一的Android对象为底层Android API提供了一个接口。
import android
droid = android.Android()
# example using the text to speech facade
droid.ttsSpeak('hello world')
Each language has pretty much the same API. You can even use the JavaScript API inside webviews.
每种语言的API都差不多。您甚至可以在webviews内使用JavaScript API。
var droid = new Android();
droid.ttsSpeak('hello from js');
User Interfaces
For user interfaces, you have three options:
对于用户界面,您有三个选项:
- You can easily use the generic, native dialogues and menus through the API. This is good for confirmation dialogues and other basic user inputs.
- 您可以通过API轻松地使用通用的、本机的对话和菜单。这有利于确认对话和其他基本用户输入。
- You can also open a webview from inside a Python script, then use HTML5 for the user interface. When you use webviews from Python, you can pass messages back and forth, between the webview and the Python process that spawned it. The UI will not be native, but it is still a good option to have.
- 您还可以从Python脚本中打开webview,然后使用HTML5作为用户界面。当您使用Python的webviews时,您可以在webview和派生它的Python进程之间来回传递消息。UI不是本地的,但它仍然是一个不错的选择。
- There is some support for native Android user interfaces, but I am not sure how well it works; I just haven't ever used it.
- 对原生Android用户界面有一些支持,但我不确定它的效果如何;我只是从来没用过。
You can mix options, so you can have a webview for the main interface, and still use native dialogues.
您可以混合选项,因此可以为主界面设置webview,并且仍然使用本机对话。
QPython
There is a third party project named QPython. It builds on SL4A, and throws in some other useful stuff.
还有一个名为QPython的第三方项目。它建立在SL4A上,并抛出一些其他有用的东西。
QPython gives you a nicer UI to manage your installation, and includes a little, touchscreen code editor, a Python shell, and a PIP shell for package management. They also have a Python 3 port. Both versions are available from the Play Store, free of charge. QPython also bundles libraries from a bunch of Python on Android projects, including Kivy, so it is not just SL4A.
QPython为您提供了一个更好的UI来管理您的安装,并包括一个小的触摸屏代码编辑器、一个Python shell和一个用于包管理的PIP shell。他们还有一个Python 3端口。两个版本都可以从游戏商店免费下载。QPython还在Android项目(包括Kivy)上捆绑了大量Python库,所以它不仅仅是SL4A。
Note that QPython still develop their fork of SL4A (though, not much to be honest). The main SL4A project itself is pretty much dead.
请注意,QPython仍然开发他们的SL4A的分支(尽管,说实话)。主要的SL4A项目本身已经死了。
- SL4A Project (now on GitHub): https://github.com/damonkohler/sl4a
- SL4A项目(现在在GitHub上):https://github.com/damonkohler/sl4a。
- SL4A Python 3 Port: https://code.google.com/p/python-for-android/wiki/Python3
- SL4A Python3端口:https://code.google.com/p/pythonforandroid/wiki/python3。
- QPython Project: http://qpython.com
- QPython项目:http://qpython.com
#8
52
As a Python lover and Android programmer, I am sad to say this is not really a good way to go. There are two problems.
作为一个Python爱好者和Android程序员,我很遗憾地说,这并不是一个好方法。有两个问题。
One problem is that there is a lot more than just a programming language to the Android development tools. A lot of the Android graphics involve XML files to configure the display, similar to HTML. The built-in java objects are really integrated with this XML layout, and it's a lot easier than writing your own code to go from logic to bitmap.
一个问题是,Android开发工具不仅仅是一种编程语言。很多Android图形都涉及到XML文件来配置显示,类似于HTML。内置的java对象实际上与XML布局集成在一起,这比编写自己的代码从逻辑到位图要容易得多。
The other problem is that the G1 (and probably other Android devices for the near future) are really not that fast. 200 MHz processors, and RAM is very limited. Even in Java you have to do a decent amount of rewriting-to-avoid-more-object-creation if you want to make your app perfectly smooth. Python is going to be too slow for a while still on mobile devices.
另一个问题是G1(以及可能在不久的将来使用的其他Android设备)真的没有那么快。200 MHz处理器,RAM非常有限。即使是在Java中,如果你想让你的应用程序完美的平滑,你也需要做大量的重新编写——避免更多的对象创建。在移动设备上,Python的速度将会太慢。
#9
30
Not at the moment and you would be lucky to get Jython to work soon. If you're planning to start your development now you would be better off with just sticking to Java for now on.
现在还没有,你很快就能让Jython工作了。如果你正打算开始你的开发,你最好现在就坚持用Java。
#10
26
Using SL4A (which has already been mentioned by itself in other answers) you can run a full-blown web2py instance (other python web frameworks are likely candidates as well). SL4A doesn't allow you to do native UI components (buttons, scroll bars, and the like), but it does support WebViews. A WebView is basically nothing more than a striped down web browser pointed at a fixed address. I believe the native Gmail app uses a WebView instead of going the regular widget route.
使用SL4A(已经在其他答案中已经提到过),您可以运行一个成熟的web2py实例(其他python web框架也可能是候选的)。SL4A不允许您执行本机UI组件(按钮、滚动条等),但它支持WebViews。WebView基本上就是一个带条纹的web浏览器指向一个固定的地址。我相信本地Gmail应用程序使用的是WebView而不是常规的小部件路由。
This route would have some interesting features:
这条路线会有一些有趣的特点:
- In the case of most python web frameworks, you could actually develop and test without using an android device or android emulator.
- 在大多数python web框架的情况下,您实际上可以在不使用android设备或android模拟器的情况下开发和测试。
- Whatever Python code you end up writing for the phone could also be put on a public webserver with very little (if any) modification.
- 不管你最后为手机写的是什么Python代码,都可以放在一个非常小(如果有的话)的公共网络服务器上。
- You could take advantage of all of the crazy web stuff out there: query, HTML5, CSS3, etc.
- 你可以利用所有疯狂的网络内容:查询、HTML5、CSS3等等。
#11
25
Kivy
I want to post this as an extension of what @JohnMudd has already answered (but please bear with me as English isn't my first language)
我想把这个作为@JohnMudd已经回答的扩展(但是请容忍我,因为英语不是我的第一语言)
It has been years since then, and Kivy has evolved to v1.9-dev. The biggest selling point of Kivy, in my opinion, is its cross-platform compatibility. You can code and test under your local environment (Windows/*nix etc.), you can also build, debug and package your app to run on your Android/iOS/Mac/Windows devices.
从那时起已经有好几年了,Kivy已经发展到v1.9-dev。在我看来,Kivy最大的卖点就是它的跨平台兼容性。您可以在您的本地环境(Windows/*nix等)下进行编码和测试,您还可以在您的Android/iOS/Mac/Windows设备上构建、调试和打包您的应用程序。
With Kivy's own KV language, you can code and build the GUI interface easily (it's just like Java XML, but rather than TextView etc., KV has its own ui.widgets
for the similar translation), which is in my opinion quite easy to adopt.
通过Kivy自己的KV语言,您可以轻松地编写和构建GUI界面(它就像Java XML,而不是TextView等等,KV有它自己的ui)。小部件的类似翻译),这是我认为很容易采用的。
Currently Buildozer and python-for-android are the most recommended tools to build/package your apps. I have tried them both and can firmly say that they make building Android apps with Python a breeze. Users who feel comfortable in their console/terminal/command prompt should have no problems using them, and their guides are well documented, too.
目前,Buildozer和python-for-android是构建/打包应用程序的最推荐工具。我已经尝试过这两种方法,并且可以肯定地说,他们用Python轻松构建Android应用程序。在控制台/终端/命令提示符中感到舒适的用户使用它们时应该没有问题,而且它们的向导也有良好的文档记录。
Furthermore, iOS is another big selling point of Kivy, provided that you can use the same code base with little changes required to test-run on your iOS device, via kivy-ios Homebrew tools, although Xcode is required for the build before running on their devices (AFAIK the iOS Simulator in Xcode currently doesn't work for the x86-architecture build). There are also some dependency issues which must be manually compiled and fiddled around with in Xcode to have a successful build, but they wouldn't be too difficult to resolve and people in Kivy Google Group are really helpful too.
此外,iOS是Kivy的另一大卖点,提供,您可以使用相同的代码基的小变化要求也是你的iOS设备上,通过kivy-ios自酿酒工具,尽管Xcode需要构建在他们的设备上运行(AFAIK iOS模拟器在Xcode中目前对x86架构构建不起作用)。还有一些依赖性问题,必须手动编译,并在Xcode中进行处理,以获得成功的构建,但是它们不会太难解决,Kivy谷歌组的人员也很有帮助。
With all being said, users with good Python knowledge should have no problem picking up the basics in weeks (if not days) to build some simple apps.
尽管如此,拥有良好的Python知识的用户应该在几个星期(如果不是几天)的基础上找到一些简单的应用程序。
Also worth mentioning is that you can bundle (build recipes) your Python modules with the build so users can really make use of many existing libraries Python bring us, like Requests & PIL etc. through Kivy's extension support.
值得一提的是,您可以将您的Python模块打包(构建菜谱),这样用户就可以通过Kivy的扩展支持,真正地利用许多现有的库Python带给我们,比如请求和PIL。
Sometimes your application requires functionality that is beyond the scope of what Kivy can deliver. In those cases, it is necessary to resort to external software libraries. Given the richness of the Python ecosystem, there is already a lot of software libraries that you can simply import and use right away.
有时,您的应用程序需要的功能超出了Kivy所能交付的范围。在这种情况下,有必要求助于外部软件库。考虑到Python生态系统的丰富程度,已经有很多软件库可以直接导入和使用。
The last but not the least, if you are going to use Kivy for more serious/commercial projects, you may find existing modules not satisfactory. There are some workable solutions though, with the "work in progress" of pyjnius for Android, and pyobjus. Users can now access Java/Objective-C classes through those modules to control some of the native APIs.
最后但不是最不重要的,如果你打算用Kivy来做更严肃的/商业项目,你可能会发现现有的模块并不令人满意。不过,有一些可行的解决方案,比如Android的pyjnius的“工作进展”和pyobjus。用户现在可以通过这些模块访问Java/Objective-C类来控制一些本地api。
My experience in Kivy is that it will find its best fit with seasoned Python programmers and some serious programmers who want rapid development or simple code base maintenance. It runs well on multiple platforms, albeit not really with the native feeling.
我在Kivy的经验是,它将发现它最适合于经验丰富的Python程序员和一些需要快速开发或简单代码基础维护的严肃程序员。它在多个平台上运行良好,尽管不是真正的本地感觉。
I do hope some Python app programmers find this information useful and start taking a look at Kivy. It can only get better (with more support and as libraries/modules get ported) if there is great interest from the community.
我确实希望一些Python应用程序的程序员觉得这些信息有用,并开始看一看Kivy。如果社区有很大的兴趣,它只会变得更好(有更多的支持和库/模块的移植)。
P.S. I have no relationship with Kivy whatsoever, I'm merely a programmer who really likes the idea of bringing Python coding fun to mobile/cross-platform development.
我和Kivy之间没有任何关系,我只是一个真正喜欢把Python编程的乐趣带到移动/跨平台开发的程序员。
#12
18
I use the QPython application. It has an editor, a console, and you can run your Python programs with it. The application is free, and the link is http://qpython.com/.
我使用了QPython应用程序。它有一个编辑器、一个控制台,您可以使用它运行您的Python程序。该应用程序是免费的,链接是http://qpython.com/。
#13
17
From the Python for android site:
android站点的Python:
Python for android is a project to create your own Python distribution including the modules you want, and create an apk including python, libs, and your application.
android的Python是一个创建您自己的Python发行版的项目,包括您想要的模块,并创建一个apk,包括Python、libs和您的应用程序。
#14
14
Yet another attempt: https://code.google.com/p/android-python27/
另一个尝试:https://code.google.com/p/android-python27/
This one embed directly the Python interpretter in your app apk.
这一个直接嵌入你的应用程序apk中的Python解释器。
#15
12
There are several ways to use Python on Android.
有几种方法可以在Android上使用Python。
BeeWare is a collection of tools for building native user interfaces
BeeWare是一个用于构建本地用户界面的工具集。
Chaquopy is a plugin for Android Studio's Gradle-based build system.
Chaquopy是Android Studio基于等级的构建系统的插件。
Kivy is a cross-platform OpenGL-based user interface toolkit.
Kivy是一个基于opengl的用户界面工具包。
pyqtdeploy is a tool for deploying PyQt applications.
pyqtdeploy是部署PyQt应用程序的工具。
QPython is an on-device script engine and development environment.
QPython是一个设备上的脚本引擎和开发环境。
SL4A (Scripting Layer for Android), originally named ASE (Android Scripting Environment), is a set of "facades" which expose a greatly-simplified subset of the Android API.
SL4A (Android的脚本层),最初命名为ASE (Android脚本环境),是一组“facades”,它公开了Android API的一个非常简化的子集。
PySide (the Python binding for the Qt toolkit) has some preliminary support for Android.
PySide(用于Qt工具包的Python绑定)对Android有一些初步的支持。
Although Android's primary programming language is Java, there is no known port of Jython to the platform. Android support in BeeWare is achieved using VOC, a tool that compiles Python source code to Java class files. This allows Python code to be executed as a native binary on the JVM. https://wiki.python.org/moin/Android
虽然Android的主要编程语言是Java,但是没有已知的Jython端口。在BeeWare中,Android的支持是通过使用VOC来实现的,VOC是将Python源代码编译成Java类文件的工具。这允许将Python代码作为本地二进制代码在JVM上执行。https://wiki.python.org/moin/Android
#16
8
You can run your Python code using sl4a. sl4a supports Python, Perl, JRuby, Lua, BeanShell, JavaScript, Tcl, and shell script.
您可以使用sl4a运行您的Python代码。sl4a支持Python、Perl、JRuby、Lua、BeanShell、JavaScript、Tcl和shell脚本。
You can learn sl4a Python Examples.
您可以学习sl4a Python示例。
#17
7
There's also python-on-a-chip possibly running mosync: google group
还有python-on-a-chip可能运行的mosync:谷歌组。
#18
7
Another option if you are looking for 3.4.2 or 3.5.1 is this archive on GitHub.
如果您要查找3.4.2或3.5.1,则另一个选项是GitHub上的存档。
Python3-Android 3.4.2 or Python3-Android 3.5.1
Python3-Android 3.4.2或Python3-Android 3.5.1。
It currently supports Python 3.4.2 or 3.5.1 and the 10d version of the NDK. It can also support 3.3 and 9c, 11c and 12
它目前支持Python 3.4.2或3.5.1和NDK的10d版本。它还可以支持3.3和9c、11c和12。
It's nice in that you simply download it, run make and you get the .so or the .a
它很好,你只要下载它,运行make,你就能得到so或a。
I currently use this to run raw Python on android devices. With a couple modifications to the build files you can also make x86 and armeabi 64 bit
我现在使用它在android设备上运行原始的Python。通过对构建文件进行一些修改,您还可以使x86和armeabi 64位。
#19
6
Didn't see this posted here, but you can do it with Pyside and Qt now that Qt works on Android thanks to Necessitas.
在这里没有看到这个帖子,但是你可以用Pyside和Qt来做,因为Qt在Android上的工作是需要的。
It seems like quite a kludge at the moment but could be a viable route eventually...
目前看来,这是一种相当笨拙的操作,但最终可能是可行的。
http://qt-project.org/wiki/PySide_for_Android_guide
http://qt-project.org/wiki/PySide_for_Android_guide
#20
6
You can use Termux application:
您可以使用Termux应用程序:
Note that apt install python install python 3. for python 2 you shoud call apt install python2.
注意,apt安装python安装python 3。对于python2,您应该调用apt安装python2。
Some demos here: https://www.youtube.com/watch?v=fqqsl72mASE
一些演示:https://www.youtube.com/watch?v=fqqsl72mASE
And also the github page: https://github.com/termux
还有github页面:https://github.com/termux。
#21
5
You can use QPython:
您可以使用QPython:
It has a Python Console, Editor, as well as Package Management / Installers
它有一个Python控制台、编辑器以及包管理/安装程序。
http://qpython.com/
It's an open source project with both Python 2 and Python 3 implementations. You can download the source and the Android .apk files directly from github.
它是一个使用Python 2和Python 3实现的开放源码项目。您可以直接从github下载源代码和Android .apk文件。
QPython 2: https://github.com/qpython-android/qpython/releases
QPython 2:https://github.com/qpython-android/qpython/releases
QPython 3: https://github.com/qpython-android/qpython3/releases
QPython 3:https://github.com/qpython-android/qpython3/releases
#22
5
There is an app called QPython3 in playstore which can be used for both editing and running python script.
在playstore中有一个名为QPython3的应用程序,可以用于编辑和运行python脚本。
Playstore链接
Another app called Termux in which you can install python using command
另一种名为Termux的应用程序可以使用命令来安装python。
pkg install python
Playstore链接
#23
3
One more option seems to be pyqtdeploy which citing the docs is:
另一个选项似乎是pyqtdeploy,引用文档的是:
a tool that, in conjunction with other tools provided with Qt, enables the deployment of PyQt4 and PyQt5 applications written with Python v2.7 or Python v3.3 or later. It supports deployment to desktop platforms (Linux, Windows and OS X) and to mobile platforms (iOS and Android).
与Qt提供的其他工具结合使用的工具,可以部署PyQt4和PyQt5应用程序,使用Python v2.7或Python v3.3或更高版本编写。它支持部署到桌面平台(Linux、Windows和OS X)和移动平台(iOS和Android)。
According to Deploying PyQt5 application to Android via pyqtdeploy and Qt5 it is actively developed, although it is difficult to find examples of working Android apps or tutorial on how to cross-compile all the required libraries to Android. It is an interesting project to keep in mind though!
通过pyqtdeploy和Qt5将PyQt5应用程序部署到Android上,它是积极开发的,尽管很难找到运行Android应用程序的例子,也很难找到如何将所有必需的库编译成Android的教程。不过,这是一个很有趣的项目。
#24
1
Chaquopy
Chaquopy is a plugin for Android Studio's Gradle-based build system. It focuses on close integration with the standard Android development tools.
Chaquopy是Android Studio基于等级的构建系统的插件。它专注于与标准的Android开发工具的紧密集成。
-
It provides complete APIs to call Java from Python or Python from Java, allowing the developer to use whichever language is best for each component of their app.
它提供了完整的api,可以从Python或Python中调用Java,允许开发人员在应用程序的每个组件中使用最适合的语言。
-
It can automatically download PyPI packages and build them into an app, including selected native packages such as NumPy.
它可以自动下载PyPI包并将其构建到一个应用程序中,包括选择的本地包(如NumPy)。
-
It enables full access to all Android APIs from Python, including the native user interface toolkit (example pure-Python activity).
它允许从Python中完全访问所有Android api,包括本地用户界面工具箱(例如pure-Python活动)。
This is a commercial product, but it's free for open-source use and will always remain that way.
这是一个商业产品,但它是免费的开源使用并且将一直保持这种方式。
(I am the creator of this product.)
(我是这个产品的创造者。)
#25
0
Take a look at BeeWare. At the moment of answering this question it is still in early development. It's aim is to be able to create native apps with Python for all supported operating systems, including Android.
看一看BeeWare。在回答这个问题的时候,它还处于早期发展阶段。它的目标是能够用Python为所有支持的操作系统(包括Android)创建本地应用程序。