ios上运行python
This holiday I discovered Pythonista, and my mind was blown.
这个假期,我发现了Pythonista ,这让我很震惊 。
In the iOS world, Pythonista is a well known quantity. I can find articles about it from sources like MacStories from back in 2012. Back then it was fairly rudimentary: no support for folders, no ability to import code from outside the app (at least not easily), and limited ability to interact with lots of parts of the OS. But it was clearly useful to a lot of people as a powerful tool for automating their iOS devices.
在iOS世界中,Pythonista是众所周知的数量。 我可以从2012年的 MacStories等来源找到有关此文章的文章。 那时还很初级:不支持文件夹,没有能力从应用程序外部导入代码(至少不容易),并且与操作系统的许多部分进行交互的能力有限。 但这对于许多人来说显然是有用的,它是使他们的iOS设备自动化的强大工具。
However, it seems like many of the people who were using this to automate their iOS devices weren’t Python developers, and most Python developers didn’t seem to be fully aware that it existed. If they were, they would have found that 2012’s little Python interpreter in an iOS app has turned into a nearly fully-fledged Python programming environment. How did this happen? In no small part, it’s down to Stash.
但是,似乎许多使用此工具来自动化其iOS设备的人都不是Python开发人员,而且大多数Python开发人员似乎都没有完全意识到它的存在。 如果是这样的话,他们会发现2012年iOS应用程序中的小型Python解释器已经变成了几乎成熟的Python编程环境。 这怎么发生的? 在很大程度上,这取决于Stash 。
Stash is a pure-Python implementation of a Bash-like shell for Pythonista. Essentially, you download and install it and then execute a helper script inside Pythonista. That helper script opens up a new console window and gives you, amazingly, a shell prompt with a filesystem:
Stash是Pythonista的Bash式外壳的纯Python实现。 本质上,您可以下载并安装它,然后在Pythonista中执行一个帮助程序脚本。 该帮助程序脚本将打开一个新的控制台窗口,并为您提供了一个带有文件系统的shell提示:
This is a little bit mind blowing. But it gets better because, you see, this shell has got some game. It comes with a few killer applications essentially reimplemented using Python, the most notable of which are git
and pip
. Now, to be clear, these applications are very much reimplementations of the standard tools: they often don’t have the same syntax as the originals and they have weird limitations that the others don’t have. But together they let you do this:
这有点令人不寒而栗。 但是它会变得更好,因为您知道该外壳具有一些功能。 它带有一些使用Python重新实现的杀手级应用程序,其中最著名的是git
和pip
。 现在,很明显,这些应用程序是标准工具的重新实现:它们通常与原始应用程序没有相同的语法,并且它们具有其他应用程序没有的奇怪限制。 但是,他们让您一起做到这一点:
That’s me installing a Python package from PyPI and cloning and git repository. And the clone works: all the code is now available, version controlled, in my Pythonista filesystem, as you can see in the sidebar below:
那就是我从PyPI安装Python包,然后克隆和git仓库。 克隆也可以正常工作:在我的Pythonista文件系统中,所有代码现在都可用,受版本控制,如下面的侧栏中所示:
This is pretty big! Essentially I now have access to every pure-Python module that has ever been published, fully executable, on my iOS device. And they work too. Some quick investigation revealed that even somewhat unexpected things work: for example, the curio asynchronous I/O framework for Python 3.5+ runs unmodified, implying that sockets, selectors, and even TLS behave as expected. All of my HTTP/2 toolchain runs as well, meaning that I was able to whip up a quick HTTP/2 client in pure-Python using curio and hyper-h2 and that was capable of doing a complete HTTP/2 request from my iPad, as you can see below:
这个很大! 从本质上来说,我现在可以访问我的iOS设备上所有已发布的,完全可执行的纯Python模块。 他们也工作。 一些快速调查显示,即使有些出乎意料的事情也能起作用:例如,用于Python 3.5+的curio异步I / O框架未修改就运行,这意味着套接字,选择器甚至TLS的行为均符合预期。 我所有的HTTP / 2工具链也都正常运行,这意味着我能够使用curio和hyper-h2在纯Python中生成一个快速的HTTP / 2客户端,并且能够从我的iPad发出完整的HTTP / 2请求,如下所示:
This means that we’re very close to having a fully-fledged Python programming environment on our iOS devices. The advantages of this are pretty substantial. Firstly, for those who want it, it opens up a world of scripting and automation opportunities that iOS has previously hidden away. Pythonista has a lot of hooks into the operating system that allow you to write applets or helper functions that can automate boring tasks. The folks over at MacStories have written an enormous number of posts demonstrating some of the cool things that Pythonista can do to automate their workflows. When you add in to this the fact that there is now a fairly functional PyPI client available to obtain any helper libraries you might need, you have the ability to write almost arbitrary code that can operate on data made available elsewhere in the OS. This is an enormously powerful tool, and for anyone who is really serious about being a hardcore iOS power user it is absolutely worth investigating.
这意味着我们非常接近在iOS设备上拥有完整的Python编程环境。 这样的优点是相当可观的。 首先,对于那些想要它的人,它打开了iOS以前隐藏的脚本和自动化机会的世界。 Pythonista在操作系统中有很多钩子,可让您编写可自动执行无聊任务的applet或辅助函数。 MacStories的人们写了许多文章,展示了Pythonista可以做的一些很酷的事情来自动化他们的工作流程。 当您添加一个事实,即现在可以使用功能相当强大的PyPI客户端来获取您可能需要的任何帮助程序库时,您就可以编写几乎任意的代码,以对OS上其他地方可用的数据进行操作。 这是一个非常强大的工具,对于真的很想成为iOS核心用户的任何人,绝对值得研究。
But more importantly, it’s one step closer to not needing a full PC to work on Python code. For my part, I’ve been interested in trying to move away from needing a laptop for travel purposes. There are a number of boring reasons for this, but ultimately my requirement has been that I needed something like a proper Python shell on an iOS device to consider swapping over to an iPad as travel computer.
但更重要的是,与不需要完整的PC来处理Python代码相比,这又迈出了一步。 就我而言,我一直想摆脱旅行所需的笔记本电脑。 有很多无聊的原因 ,但最终我的要求是,我需要在iOS设备上使用适当的Python shell之类的东西,才能考虑作为旅行计算机交换到iPad上。
Amazingly, this puts us pretty close by. An upcoming release of Stash is going to support the pip console_scripts
extensions, which should make it possible to install and run py.test
(my preferred testing framework). If that happens, I’ll be in possession of an environment with git support and the ability to code and run my tests on the go, with no network connection required. At that point I may finally be in a position where I can do a reasonable amount of work from my iOS device.
令人惊讶的是,这使我们非常接近。 Stash即将发布的版本将支持pip console_scripts
扩展,这将使安装和运行py.test
(我的首选测试框架)成为可能。 如果发生这种情况,我将拥有一个具有git支持并且能够随时随地编写和运行测试的功能的环境,而无需网络连接。 到那时,我可能终于可以在我的iOS设备上做一些合理的工作了。
This environment is still not perfect. There are some alarming bug reports about the git logic inside Pythonista, which means I’d rather use Working Copy, but it seems that right now Pythonista isn’t able to treat Working Copy as a full-fledged document source. In my ideal world Working Copy would be able to expose the whole git tree to Pythonista so that Pythonista could “mount” it on the filesystem, but it doesn’t immediately seem to be possible. If it became possible, I’d consider the combination of those two applications as being pretty close to the “killer app” for Python development on iOS.
这种环境仍然不是完美的。 关于Pythonista内部git逻辑的一些令人震惊的错误报告,这意味着我宁愿使用Working Copy ,但现在看来Pythonista无法将Working Copy视为完整的文档源。 在我的理想世界中,Working Copy可以将整个git树公开给Pythonista,以便Pythonista可以将其“挂载”到文件系统上,但是似乎不可能立即进行。 如果有可能,我认为这两个应用程序的组合非常接近iOS上用于Python开发的“杀手级应用程序”。
Regardless, this is one of the most exciting discoveries I’ve made in a long time. I’m able to write genuine Python code to interact with my iOS device without needing to build an entire app to do it. This drastically reduces the overhead in scripting my operating systems, which is a huge leap forward in terms of flexibility.
无论如何,这是我很长一段时间以来最激动人心的发现之一。 我能够编写真正的Python代码来与我的iOS设备进行交互,而无需构建整个应用程序来完成。 这大大减少了编写操作系统脚本的开销,这在灵活性方面是一个巨大的飞跃。
It also opens a neat world of physical computing. As anyone who knows about computing education can tell you, physical computing is enormously important for educating children in computation because it provides them with direct feedback, demonstrating the utility of computing in an immediate manner. This is commonly done for smaller children with devices like the BBC Micro:bit, but for older children the most obvious device to use is their phone. For a long time, Android devices have been the easiest devices to use for this, but it’s good to see that iOS devices are now open to being used in this way.
它还为物理计算打开了一个整洁的世界。 正如任何了解计算教育的人都可以告诉您的那样,物理计算对于教育儿童进行计算非常重要,因为它可以为孩子提供直接的反馈,从而立即证明了计算的效用。 这通常是针对年龄较小的孩子使用的设备,例如BBC Micro:bit ,但是对于年龄较大的孩子,最明显的设备是手机。 长期以来,Android设备一直是最容易用于此目的的设备,但是很高兴看到iOS设备现在可以以这种方式使用。
This is very cool, and I’m really looking forward to seeing what the community does next.
这非常酷,我非常期待看到社区接下来要做的事情。
翻译自: https://www.pybloggers.com/2016/12/python-on-ios/
ios上运行python