• How to
  • Apps
  • Games
  • MOD APK
  • Root
  • About Us
  • Privacy Policy
  • Disclaimer
  • Contact Us
  • Write For Us
AndroidFit
  • How to
  • Apps
  • Games
  • MOD APK
  • Root
AndroidFit
Home»Android Apps»How to Install Python on Termux

How to Install Python on Termux

By AndroidFitUpdated:February 20, 2023 Android Apps
Share Facebook WhatsApp Twitter Pinterest LinkedIn Reddit Telegram Email
How To Install Python on Android using Termux
How To Install Python on Android using Termux
Share
Facebook WhatsApp Twitter LinkedIn Pinterest Email VKontakte Telegram

Ever wondered if you can run Python scripts on your smartphone? Writing Python code on touchscreen devices with small displays can be tough, but it’s convenient when you need to quickly test a Python script but don’t want to get out of bed and fire up your PC.

Installing Python on a computer is easy. But what if you want to code in Python on Android? You can install Python using Termux.

Installing Python on an Android smartphone using Termux is easy. We’ll walk you through the entire process, from downloading Termux to running your first Python program on an Android device.

Install Termux on Android

Termux is a terminal emulator for Android. To install it on your smartphone, head over to F-Droid and download the latest APK available.

Download: Termux (F-Droid)

Once downloaded, locate and tap on the APK file to begin the installation. When asked for confirmation, tap Install.

Although Termux is available to download from the Google Play Store, as of this writing, the pre-configured repositories throw a 404 error when you try to install a package or update existing ones.

How to Install Python on Termux

Before installing Python, the first step is to update existing packages. The default package manager on Termux is pkg, which is quite similar to Debian or Ubuntu’s APT in terms of syntax and arguments.

To update packages on Termux, run:

pkg upgrade

When prompted for Y/N confirmations, tap Enter to go with the defaults. You’ll have to do this a couple of times during the process.

How to Install Python on Termux
How to Install Python on Termux

Then, enter the following command to install Python:

pkg install python

Enter Y when prompted for confirmation.

If you wish to install Python 2 instead, run:

pkg install python2

PIP and PIP2 will be installed along with the python and python2 packages, respectively, so rest assured you can install libraries and modules that you frequently work with.

Running the Python Interactive Shell

With Python installed, it’s time to test whether the installation was successful. In the terminal, enter “python” to launch the interactive shell (“python2” if you installed the old version).

If everything went well, you’ll see the version of Python listed at the top along with some helpful information. As with any other language, test out the interpreter by typing the following statement to print “Hello, World“:

print("Hello, World")

The output will display the string “Hello, World” and then switch back to input mode. When you’ve played with the interactive shell enough and want to go back to the terminal, type “exit()” and hit Enter.

Writing Your First Python Script on Termux

To take it a step further, why not create a Python script and execute it using Termux? To begin, first open nano, a terminal-based text editor for Linux. If you want to use another text editor, feel free to install it with the pkg install command.

Enter the following to create a new Python script file in the current directory:

nano script.py

Add the following lines of code to the file:

print("Hello, World")
name = input("What's your name? ")
print("Enjoy Python programming on Termux", name)

To save changes to the file, tap the Ctrl button and hit O. Then, press Enter to save the file. To exit nano, tap Ctrl and X.

Writing Your First Python Script on Termux
Writing Your First Python Script on Termux

Run the script by issuing the following command:

python script.py

Python 2 users would need to substitute “python” in the above command with “python2”. The program will display “Hello, World” and ask for your name. Once you specify that and tap Enter, it’ll output the final string with your name appended at the end.

Faq

Can Termux run python?

A few python packages are available from termux’s package manager (for python3 only), and should be installed from there to avoid compilation errors. This is the case for: numpy, pkg install python-numpy. electrum, pkg install electrum.

How do I run a .PY file in Termux Android?

Move to the newly created folder with cd ./termux/tasker and use vim or nano to create your script. You’ll probably have to do pkg install python too. Then move to Tasker, create a task and name it whatever you want. Inside the task, add a Plugin:Termux command and set the config to the script you’re running.

Can I install Django with Termux?

Yes, you can do it. After creating Creating a virtual environment, you can instal the Django framework

Also check this

  1. Mini Militia Cheats, Chat Codes, Hacks and Tips (Doodle Army 2 Mini militia tips)
  2. Little Big City 2 Mod APK for Free Unlimited Diamonds, Money – 100% working
  3. Is Signal Tracking Performed When the Phone is Off?
  4. What is OsuLogin on Android? Know everything about OsuLogin
  5. How to Block Any Website on Android Devices
Share. Facebook Twitter Pinterest LinkedIn Email Telegram WhatsApp
Previous ArticleApps That Are Changing The Automotive Industry
Next Article How to Bypass Google Account Verification After Reset [2023 Update]
AndroidFit
  • Website
  • Facebook

Hi, Here's AndroidFit admin!! I always try to give my best to this website..

Related Posts

Android Apps

YouTube Go APK Download (Latest Version) for Android

September 20, 2023
Android Apps

YoWhatsApp Apk Download September 2023 Update (Anti-Ban Latest Version)

September 7, 2023
Android Apps

GBWhatsApp Download APK September 2023 – Official Latest Update (Anti-Ban)

September 7, 2023
Add A Comment

Leave A Reply Cancel Reply

Latest Posts

How to Get Zeus Free Trial in 2023 (Watch Free Videos)

September 24, 2023

How To Change Serial Number Of Your Android

September 23, 2023

How to Hide Your Phone Number on WhatsApp

September 22, 2023

How to Turn On Pocket Mode on Android

September 21, 2023

YouTube Go APK Download (Latest Version) for Android

September 20, 2023

Lulubox Pro 64-Bit Download

September 19, 2023

Game Space App APK Download Inside! [All Version]

September 16, 2023

How to Make Android Faster with Developer Options

September 11, 2023

GTA San Andreas Lite Apk Download (OBB File 200 MB)

September 10, 2023

How to Turn On/Off Wireless Display Certification under Developer Options?

September 10, 2023
© 2023 AndroidFit
  • About Us
  • Privacy Policy
  • Disclaimer
  • Contact Us
  • Write For Us

Type above and press Enter to search. Press Esc to cancel.

Ad Blocker Enabled!

Ad Blocker Enabled!
Our website is made possible by displaying online advertisements to our visitors. Please support us by disabling your Ad Blocker.