How To Install and Run Python 3.6/3.9 in Termux (Latest Guide)

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:

  1. You first need to install “Termux” on your Android device, for this you need to open “PlayStore”.
  2. Search “Termux” and click on the “install” button which is associated with Termux app from search results.
  3. Once it gets installed, simply click on “open”.Install Python 3.9 in Termux on Android
  4. As it launches, on the terminal you need to type the following command and hit “enter” to install Python 3.9:
    Paul@ninja-ide:~# Pkg install python3.9 <replace 3.9 with 3.6 for either version>
    
  5. Click “enter” as you have done from the keyboard.
  6. As you get the confirmation request simple hit “y” from keyboard and hit “enter”.How to run Python in Termux
  7. 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.
  8. 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”.
  9. You shall see python version package that has been installed on the device, this indicates that the process of installation was successful.Install Python 3.6 in Termux
  10. 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.
  11. Following is a screenshot showing us an example of how Python output would look in Termux.
  12. Now if you like to terminate Python, like in Linux, simply click “CTRL” key at first and then hit “Z” from the 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

Paul@ninja-ide:~# apt-get purge python 

Method #2: Use rm-rf to force uninstall Python

Paul@ninja-ide:~# 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:

Paul@ninja-ide:~# /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:

  1. Open the Termux terminal with root permissions.
  2. Now run the following command and click on “Allow” when asked for permissions on your phone.
    Paul@ninja-ide:~# termux-setup-storage
    
  3. This error will no longer appear!

It has been designed to provide you with many packages that 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:

Conclusion

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 if you have any .py scripts to run and don’t want to carry your laptop around.

Previous articleHow To Enable LibreOffice Dark Mode in Windows 11, 10
Next articleTop 7 Best Python VSCode and Visual Studio Extensions to Install
Paul Carruthers
Paul is an avid programmer who specializes in Python and Java with over 16 years of experience in the field. He loves automating complex tasks and creating useful scripts to streamline work and make life easier. He is also a massive fan of Linux and currently uses it as his main desktop OS. When he is not staring at code, he loves hiking and swimming in different parts of the world.

LEAVE A REPLY

Please enter your comment!
Please enter your name here