在 android 上使用 python 和 matplotlib
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18353203/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Using python and matplotlib on android
提问by marshall
Is there a way to set up python 2.7.x + matplotlib on an android tablet so that you can run simple standard python code? I would like to be able to run the same scripts I run on my Linux desktop. This is just for my own use and I don't need to distribute the code to anyone else.
有没有办法在Android平板电脑上设置python 2.7.x + matplotlib,以便您可以运行简单的标准python代码?我希望能够运行我在 Linux 桌面上运行的相同脚本。这仅供我自己使用,我不需要将代码分发给其他任何人。
As a concrete example, is it possible to run this script?
作为一个具体的例子,是否可以运行这个脚本?
import numpy as np
import matplotlib.pyplot as plt
x = np.arange(0, 5, 0.1);
y = np.sin(x)
plt.plot(x, y)
回答by Musti Hakan
ever heard of qpython? http://qpython.com/i personally never used it, but my colleague were quite handy with it so you may want to look at that
听说过 qpython 吗? http://qpython.com/我个人从来没有用过它,但我的同事用它很方便,所以你可能想看看
回答by darmat
I've read somewhere that scipy and matplotlib cannot be compiled for android, someone did it for numpy though
我在某处读到 scipy 和 matplotlib 不能为 android 编译,不过有人为 numpy 做了
https://code.google.com/p/android-scripting/issues/detail?id=260
https://code.google.com/p/android-scripting/issues/detail?id=260
回答by RoundSparrow hilltx
Is it easy, no.
容易吗,不。
Can it be done? Yes. I believe a skilled Python / Android developer could do it in 2 to 8 hours of effort.. It's a rare and complex request.
可以做到吗?是的。我相信一个熟练的 Python/Android 开发人员可以在 2 到 8 个小时的努力中完成。这是一个罕见而复杂的请求。
Why do I think it can be done? This sample: http://matplotlib.org/examples/pylab_examples/webapp_demo.html
为什么我认为可以做到?此示例:http: //matplotlib.org/examples/pylab_examples/webapp_demo.html
Using a different library, and not abstracted for data without live hardware, this sample shows me that SL4A can do web-based graphics: http://www.smartphonedaq.com/android-python-ecg.page
使用不同的库,并且没有对没有实时硬件的数据进行抽象,这个示例向我展示了 SL4A 可以做基于网络的图形:http://www.smartphonedaq.com/android-python-ecg.page
Now, if you were talking native GUI graphics in Android - then I'm focused way too much on the web methods of publishing with SL4A ;)
现在,如果您在谈论 Android 中的本机 GUI 图形 - 那么我过多地关注使用 SL4A 发布的 Web 方法;)
回答by nagordon
You could set up a cheap server (Raspberry Pi?) and create an ssh connection to it to access full python functionality through a vnc viewer android app or the shell
您可以设置一个便宜的服务器(Raspberry Pi?)并创建一个到它的 ssh 连接,以通过 vnc 查看器 android 应用程序或 shell 访问完整的 python 功能
回答by yoghurt
There is an app called Gnuroot that allows you to run a kind-of chroot (proot), where you can install a linux distro such as debian, archlinux...
For the gui, there is the option to run a vncserver for an X server and use some android vnc client app to show the screen.
有一个名为 Gnuroot 的应用程序,它允许您运行某种 chroot (proot),您可以在其中安装 linux 发行版,例如 debian、archlinux……
对于 gui,可以选择为 X 运行 vncserver服务器并使用一些 android vnc 客户端应用程序来显示屏幕。
I use the non-gui version of gnuroot and it works well. I now have a command line debian wheezy on android lollipop arm. One minor thing i miss, is armhf (hardware floating point which my nexus7's processor can do) support instead of armel (software floating point).
我使用非 gui 版本的 gnuroot,它运行良好。我现在在 android 棒棒糖臂上有一个命令行 debian wheezy。我想念的一件小事是 armhf(我的 nexus7 的处理器可以做的硬件浮点数)支持而不是 armel(软件浮点数)。
回答by Lev
You can try MathSys. It's a wrapper around Python, and it has matplotlib inside.
你可以试试MathSys。它是 Python 的包装器,里面有 matplotlib。
Unfortunately, MathSys is rather convoluted, and it's an alpha version. Apparently, nobody is working on a beta version. You'll want to write any complicated code in an external file. import
works fine in MathSys.
不幸的是,MathSys 相当复杂,而且它是一个 alpha 版本。显然,没有人在开发测试版。您需要在外部文件中编写任何复杂的代码。import
在 MathSys 中工作正常。
回答by Scooby doo
Use the linux shell, I have it git python and pip installed on my phone. I used gnuroot in the play store.. You can apt-get install python pip from there
使用 linux shell,我在手机上安装了 git python 和 pip。我在 Play 商店中使用了 gnuroot .. 你可以从那里 apt-get install python pip
回答by sri
回答by Alf
Yes, it can be done, even without root. You need the termux
app, it basically is a terminal emulator with a full Linux environment and via apt install python
, for example, you can install python
.
是的,即使没有root也可以做到。您需要该termux
应用程序,它基本上是一个具有完整 Linux 环境的终端模拟器apt install python
,例如,您可以通过 安装python
.
The main webpage is here, and it is of course available via the standard market. (The termux wikiis a helpful place.)
主网页在这里,当然可以通过标准市场获得。(termux wiki是一个有用的地方。)
回答by Steph
Here is the code, this works after installing GNURoot Debian as you said. Just a detail : my graph is exported directly in a .png
file :
这是代码,如您所说,在安装 GNURoot Debian 后即可使用。只是一个细节:我的图形直接导出到.png
文件中:
from pylab import *
import matplotlib.pyplot as plt
plt.switch_backend('agg')
x = linspace(-5, 5, 100)
y = sin(x)
plot(x, y)
out_png = 'out_file.png'
plt.savefig(out_png, dpi=150)