<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Python on Ivon's Blog</title><link>https://ivonblog.com/en-us/tags/python/</link><description>Recent content in Python on Ivon's Blog</description><generator>Hugo -- gohugo.io</generator><language>en</language><managingEditor>infoivonblog.nkfjt@aleeas.com (Ivon Huang)</managingEditor><webMaster>infoivonblog.nkfjt@aleeas.com (Ivon Huang)</webMaster><copyright>You are welcome to share articles of Ivon's Blog (ivonblog.com). Please include the original URL when citing articles, and abide by CC BY-NC-ND 4.0 license. For commercial use, please write an e-mail to me.</copyright><lastBuildDate>Sat, 12 Apr 2025 17:00:00 +0800</lastBuildDate><atom:link href="https://ivonblog.com/en-us/tags/python/index.xml" rel="self" type="application/rss+xml"/><item><title>Write Python on an Android phone: setting up a Termux Python development environment</title><link>https://ivonblog.com/en-us/posts/termux-python/</link><pubDate>Sat, 12 Apr 2025 17:00:00 +0800</pubDate><author>infoivonblog.nkfjt@aleeas.com (Ivon Huang)</author><guid>https://ivonblog.com/en-us/posts/termux-python/</guid><description>&lt;!-- Co-translated by ChatGPT --&gt;
&lt;p&gt;Sharing how to write Python programs with the Android phone app &amp;ldquo;Termux&amp;rdquo;, plus a bit of Ivon&amp;rsquo;s personal experience.&lt;/p&gt;
&lt;p&gt;Many Android apps for writing Python on phones are awkward. They can only install packages written in pure python, and they fall over as soon as they encounter wheels. Perhaps their goal is more like Duolingo, for beginners to practice, rather than building a serious Python development environment.&lt;/p&gt;
&lt;p&gt;Among them, only Termux keeps evolving. Although &lt;code&gt;pip install&lt;/code&gt; still cannot run 100% like a normal Linux environment, more and more packages are being compiled as Termux-specific versions! Through the Python packages provided by Termux, you can run some simple
Python programs and process files on your phone. Root privileges are not required.&lt;/p&gt;
&lt;p&gt;For example, install Pillow through pip and write a small program that batch-processes EXIF photo information. It reads all photos in the phone&amp;rsquo;s DCIM folder, prints the date on each photo according to EXIF information, and outputs them to another folder. (This program really works; the &lt;a href="https://gist.github.com/ivon852/7cfa3e3e4f56ee8d52eec1124d9be028" target="_blank" rel="noreferrer"&gt;source code&lt;/a&gt; is here)
&lt;img src="images/2.webp" width=300&gt;&lt;/p&gt;
&lt;p&gt;Or use &lt;code&gt;term-image&lt;/code&gt;, written in Python, to display images from the phone in the terminal.
&lt;img src="images/1.webp" width=300&gt;&lt;/p&gt;

&lt;h2 class="relative group"&gt;1. Text-only or graphical interface?
 &lt;div id="1-text-only-or-graphical-interface" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#1-text-only-or-graphical-interface" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h2&gt;
&lt;p&gt;Termux is a text-interface terminal emulator by default. You need to type commands to run Python programs. Although a graphical interface can be run through Termux X11, is it really necessary?&lt;/p&gt;
&lt;p&gt;Text-based Python programs can only output plain text, including operations such as calculating numbers, arranging stars, batch-processing files, downloading files, and so on. To write programs in a text interface, you need to learn to edit with Vim or Emacs. This is a good chance to practice operating text editors.&lt;/p&gt;
&lt;p&gt;With a graphical interface, you can run Python programs that need to display windows, draw charts, and so on. There are many choices for programming in a graphical interface, including VS Code and Jupyter Notebook, but they consume more phone resources.&lt;/p&gt;
&lt;p&gt;A graphical interface is not necessary. If you only want to write small programs, you do not necessarily need an IDE; Vim is enough.&lt;/p&gt;
&lt;p&gt;This article focuses primarily on the text environment, with graphics second.&lt;/p&gt;

&lt;h2 class="relative group"&gt;2. Run Python in Termux or proot-distro?
 &lt;div id="2-run-python-in-termux-or-proot-distro" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#2-run-python-in-termux-or-proot-distro" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h2&gt;
&lt;p&gt;Python can run directly in Termux, or you can use &lt;a href="https://ivonblog.com/en-us/posts/termux-proot-distro/" target="_blank" rel="noreferrer"&gt;proot-distro to create a Debian environment&lt;/a&gt; and then run Python inside it.&lt;/p&gt;
&lt;p&gt;What is the difference between the two? Termux&amp;rsquo;s Python packages are versions compiled for the Termux environment and run with native performance. But Termux is not a standard Linux environment, so some Python packages may not work.&lt;/p&gt;
&lt;p&gt;As for proot-distro, the environment is closer to a Linux system, so installing Python inside it has better compatibility, and Debian&amp;rsquo;s repositories have more ready-made Python packages available without relying on pip wheels. But proot-distro runs more slowly.&lt;/p&gt;
&lt;p&gt;This article focuses on the Termux environment.&lt;/p&gt;

&lt;h2 class="relative group"&gt;3. How to install Python in Termux?
 &lt;div id="3-how-to-install-python-in-termux" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#3-how-to-install-python-in-termux" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h2&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;Install &lt;a href="https://ivonblog.com/en-us/posts/how-to-use-termux/" target="_blank" rel="noreferrer"&gt;Termux&lt;/a&gt;&lt;/p&gt;</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://ivonblog.com/en-us/posts/termux-python/featured.webp"/></item><item><title>Termux has an AUR too: install more third-party packages through TUR repo</title><link>https://ivonblog.com/en-us/posts/termux-tur-repo/</link><pubDate>Thu, 09 Nov 2023 02:00:00 +0800</pubDate><author>infoivonblog.nkfjt@aleeas.com (Ivon Huang)</author><guid>https://ivonblog.com/en-us/posts/termux-tur-repo/</guid><description>&lt;!-- Co-translated by ChatGPT --&gt;
&lt;p&gt;If you treat Termux as a Linux distribution, you will find that the main package repository uses rolling updates. It uses APT as its package manager, consumes .deb packages, and the Python and Clang versions in the repository are kept as close to upstream as possible.&lt;/p&gt;
&lt;p&gt;But some packages are too new! What if I want older software? Use some third-party repository of unknown origin? At this point, you can use TUR repo to supplement packages.&lt;/p&gt;
&lt;p&gt;TUR&amp;rsquo;s full name is &lt;code&gt;Termux User Repository&lt;/code&gt;. According to maintainer licy183, TUR tries to become a &amp;ldquo;trustworthy third-party Termux package repository&amp;rdquo;. Its concept is similar to Arch Linux&amp;rsquo;s AUR, allowing users to freely submit packages.&lt;/p&gt;
&lt;p&gt;This way, users who want to install specific software do not need to add third-party PPAs or run third-party scripts.
&lt;img src="images/2e10caeb.webp" width=300 loading="lazy" alt=""&gt;&lt;/p&gt;
&lt;p&gt;Although you can see the build commands for each package in &lt;a href="https://github.com/termux-user-repository/tur" target="_blank" rel="noreferrer"&gt;TUR&amp;rsquo;s Github repository&lt;/a&gt;, TUR does not let you compile packages locally like AUR. There are no PKGBUILDs; the packages collected there are already compiled.&lt;/p&gt;
&lt;p&gt;The TUR repository specializes in collecting some &lt;del&gt;garbage&lt;/del&gt;, no, packages that are not suitable for the main repository, such as:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;GCC. The Termux main repository only has Clang; the reason is &lt;a href="https://github.com/termux/termux-packages/issues/388" target="_blank" rel="noreferrer"&gt;here&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;Precompiled PyPi executables, such as &lt;code&gt;numpy&lt;/code&gt;, &lt;code&gt;scipy&lt;/code&gt;, and &lt;code&gt;playwright&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;Old Python versions. Because Termux is rolling-release, Python versions update too quickly, and you may need to temporarily switch to an older version.&lt;/li&gt;
&lt;li&gt;Hacker software, such as &lt;code&gt;zphisher&lt;/code&gt; and &lt;code&gt;nbtscan&lt;/code&gt;. The Termux development team is very annoyed by script kiddies who watch a few Indian Youtube videos and then ask questions all over Reddit, so &lt;a href="https://github.com/termux/termux-packages/blob/master/CONTRIBUTING.md#packaging-policy" target="_blank" rel="noreferrer"&gt;the main repository states clearly&lt;/a&gt; that hacker tools are not accepted.&lt;/li&gt;
&lt;li&gt;Proprietary software&lt;/li&gt;
&lt;li&gt;Software that supports multilib&lt;/li&gt;
&lt;li&gt;Old NodeJS versions&lt;/li&gt;
&lt;li&gt;Old Clang versions&lt;/li&gt;
&lt;li&gt;Obscure software&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 class="relative group"&gt;1. Install TUR repo
 &lt;div id="1-install-tur-repo" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#1-install-tur-repo" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h2&gt;
&lt;p&gt;Open &lt;a href="https://ivonblog.com/en-us/posts/how-to-use-termux/" target="_blank" rel="noreferrer"&gt;Termux&lt;/a&gt; and install TUR repo:&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;pkg install tur-repo
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;pkg update &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; pkg upgrade&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;After that, you can use &lt;code&gt;pkg search&lt;/code&gt; to search for packages.&lt;/p&gt;
&lt;p&gt;For example, TUR Repo has the Chromium browser, which is not yet included in Termux&amp;rsquo;s main repository, as well as the text-only &lt;code&gt;carbonyl&lt;/code&gt;:
&lt;figure&gt;
 &lt;img
 class="my-0 rounded-md"
 loading="lazy"
 decoding="async"
 fetchpriority="low"
 alt=""
 src="https://ivonblog.com/en-us/posts/termux-tur-repo/images/Screenshot_20231109-010413.webp"
 onerror="this.onerror=null;this.src='https://ivonblog.com/images/cannotloadimage.avif'"
 width="512"
 height="369"&gt;&lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;Now you can finally install GCC in Termux
&lt;figure&gt;
 &lt;img
 class="my-0 rounded-md"
 loading="lazy"
 decoding="async"
 fetchpriority="low"
 alt=""
 src="https://ivonblog.com/en-us/posts/termux-tur-repo/images/Screenshot_20231109-013602.webp"
 onerror="this.onerror=null;this.src='https://ivonblog.com/images/cannotloadimage.avif'"
 width="512"
 height="366"&gt;&lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;It also includes many Python versions, so there is less need to &lt;a href="https://ivonblog.com/en-us/posts/android-termux-anaconda/" target="_blank" rel="noreferrer"&gt;install proot Anaconda&lt;/a&gt;
&lt;figure&gt;
 &lt;img
 class="my-0 rounded-md"
 loading="lazy"
 decoding="async"
 fetchpriority="low"
 alt=""
 src="https://ivonblog.com/en-us/posts/termux-tur-repo/images/Screenshot_20231109-010954.webp"
 onerror="this.onerror=null;this.src='https://ivonblog.com/images/cannotloadimage.avif'"
 width="512"
 height="570"&gt;&lt;/figure&gt;&lt;/p&gt;
&lt;p&gt;When installing specific PyPi packages through pip, you can specify the &lt;code&gt;--extra-index-url &lt;/code&gt; URL and let pip download precompiled packages from the TUR repository instead&lt;/p&gt;
&lt;div class="highlight-wrapper"&gt;&lt;div class="highlight"&gt;&lt;pre tabindex="0" class="chroma"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span class="line"&gt;&lt;span class="cl"&gt;python -m pip install &lt;span class="s2"&gt;&amp;#34;套件名稱&amp;#34;&lt;/span&gt; --extra-index-url https://termux-user-repository.github.io/pypi/&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 class="relative group"&gt;2. Submit packages to TUR
 &lt;div id="2-submit-packages-to-tur" class="anchor"&gt;&lt;/div&gt;
 
 &lt;span
 class="absolute top-0 w-6 transition-opacity opacity-0 -start-6 not-prose group-hover:opacity-100 select-none"&gt;
 &lt;a class="text-primary-300 dark:text-neutral-700 !no-underline" href="#2-submit-packages-to-tur" aria-label="Anchor"&gt;#&lt;/a&gt;
 &lt;/span&gt;
 
&lt;/h2&gt;
&lt;p&gt;The method for submitting packages is the same as in the &lt;a href="https://github.com/termux/termux-packages/wiki/Creating-new-package" target="_blank" rel="noreferrer"&gt;official repository&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Note that TUR is not the official Termux package repository. To report issues for specific packages, please report them at &lt;a href="https://github.com/termux-user-repository/tur/issues" target="_blank" rel="noreferrer"&gt;TUR&amp;rsquo;s Github repository&lt;/a&gt;.&lt;/p&gt;</description><media:content xmlns:media="http://search.yahoo.com/mrss/" url="https://ivonblog.com/en-us/posts/termux-tur-repo/featured.webp"/></item></channel></rss>