Termux is an Android terminal emulator allowing you full Linux commands in the palm of your hand. For those who did not get it, in practice it means you can install it on most of Android devices and do all you will in a full Linux development environment on the particular device. How to install and run Python 3.9 or 3.9 on Termux is very helpful for testing and on-the-go development for any Python scripts you may need to create or tweak.
What is Termux and why Install Python on it
Now, why these are not used to introduce the next generation to Linux? As Termux can be installed with a single click on PlayStore, we would argue that it is the easiest way to anyone to the world of Linux. You may need it if you are a Python developer and need to write scripts while you are working remotely or cannot access your laptop. Termux requires no root access but this also means that it might take some time and configuration to run as you like.
Keep in mind to not leave all the fun for the noobs. It has also been designed to accommodate quite of our needs for Linux development environment.
You might also run into some old hard-coded paths that it does not handle. As you do not have root access in Termux you cannot just create a symlink to fix path issues. But what you can do is create chroot jail. You can create chroot by using the PRoot package on which you shall have full control over and it shall also allow you to modify anything you want. Moreover, you can make chroots of different Linux distros.
Now, if you are fan of Fedora then what you can do is use Termux and run it in chroot jail. For more distros and installations details visit PRoot page or you can also use this script to make one.
We have given try to Termux and Ubuntu chroot, the former one came with some issues that needed to be worked on therefore your mileage might vary depending upon the Linux version you choose.
Easiest Method To Install and Run Python 3.6 or 3.9 in Termux
Installing Python 3.6 or 3.9 in Termux is easy, you need to follow the below steps in the order they are provided:
- You first need to install “Termux” on your Android device, for this you need to open “PlayStore”.
- Search “Termux” and click on the “install” button which is associated with Termux app from search results.
- Once it gets installed, simply click on “open”.
- As it launches, on the terminal you need to type the following command and hit “enter” to install Python 3.9:
[email protected]:~# Pkg install python3.9 <replace 3.9 with 3.6 for either version>
- Click “enter” as your done from the keyboard.
- As you get the confirmation request simple hit “y” from keyboard and hit “enter”.
- Wait for the installation process to complete, at the end you should see “$” character which indicates that the process has run to completion, freeing the terminal.
- Now, let’s check to see whether it has been installed on the device or not, for this you need to type in “python” on the terminal and hit “enter”.
- You shall see python version package which has been installed on the device, this indicated that the process of installation was successful.
- At this point, you can begin to code in Python from an Android device, as you are done typing the python line click “enter” to see the output. The process is very similar to Python installation in Kali Linux.
- Following a screenshot showing us an example of how python output would look in Termux.
- Now if you like to terminate Python, same like in Linux, simply click “CTRL” key at first and then hit “Z” from keyboard. This shall terminate the process running, which is python in our case.
Note: If you are seeing errors with Installing Python in Termux, please follow the steps above carefully and make sure step 4 and 5 are not missed.
ALSO SEE: How To Install Python 3 on Chromebooks (Tutorial).
How To Uninstall Python 3.6 or 3.9 in Termux
If you no longer require Python to be installed in Termux or the pycache is taking up a lot of space you can simply uninstall it. To Uninstall Python from Termux simply run the below commands:
Method #1: Use Apt-get purge
[email protected]:~# apt-get purge python
Method #2: Use rm-rf to force uninstall Python
[email protected]:~# rm -rf /usr/lib/python
Warning: Be careful when using rm-rf, as it permanently deletes and you may cause damage to Termux if you end up wrongly deleting a directory.
Are you unable to locate the Python Termux Package? Here it is:
First of all Termux filesystem base which you can see starts around:
[email protected]:~# /data/data/com.termux/files/PaulsFolder
Under that directory, you shall be able to see the home directory as well as user directory where all the packages of Linux are installed. Though it is kind of weird but not a bigger deal, right? Well, you would be wrong, as almost every script on the planet is hard-coded for /bin/bash. If we talk about other libraries, executables as well as configuration files then these are in places inconsistent with other Linux distros.
To fix the unable to locate package in Termux error follow the 3 steps below:
- Open the Termux terminal with root permissions.
- Now run the following command and click on “Allow” when asked for permissions on your phone.
[email protected]:~# termux-setup-storage
- This error will no longer appear!
It has been designed to provide you with many packages which have been modified to correctly run. What you can do is first look there instead of going for a custom build. Moreover, you can also modify the source code of your package, though it is easy to change the path still it gets old in no time. It also comes with Termux-exec which shall redirect the path of the scripts on the fly to get them to correctly work.
ALSO SEE: Top 9 Best Python IDEs to install on Android (APK Download).
Frequently Asked Questions
Does Termux come with Python Installed by default?
Termux is only a Linux emulator, it provides basic command line functionality and does not comes with any applications or programming language support such as Python by default.
Can I Install Python on Android with Termux?
Python can be installed on your Android smartphone using Termux which is a Linux emulator. Alternatively, you can also use apps such as PyDroid.
Other Python Installation articles for you:
- How To Install Python 3.10 on Ubuntu Linux.
- Step-by-step guide for Python 3 Installation on Windows 11.
- Download PyDroid 3 Premium App APK and Run Python on Android.
Termux is the closest experience you will get of a Linux terminal in Linux. This is why a lot of tech-savvy audiences have it installed along with programmers and developers for their own testing. How to install Python 3.6/3.9 in Termux is a must of you have any .py scripts to run and don’t want to carry your laptop around.