Install Python
Before using Python in Termux, you need to install it on your device. To install Python, open the Termux terminal and type the following command:
This command will install Python on your device.
pkg install python
This command will install Python on your device.
Create and Run a Python Script
After installing Python, you can create and run Python scripts directly in the Termux terminal. Here’s an example:
Open the Termux terminal and type the following command to create a new file named
In the text editor, type the following Python code:
Press
To run the script, type the following command in the Termux terminal:
This command will execute the
Open the Termux terminal and type the following command to create a new file named
hello.py
:nano hello.py
In the text editor, type the following Python code:
print("Hello, world!")
Press
Ctrl + X
to exit the text editor and save the file.To run the script, type the following command in the Termux terminal:
python hello.py
This command will execute the
hello.py
script and print “Hello, world!” in the terminal.Install Additional Python Packages (Optional)
If you need to use additional Python packages in your scripts, you can install them using the
pkg install python-pip
After installing, you can use it to install other Python packages. For example, installing the
pip
package manager. To install, type the following command in the Termux terminal:pkg install python-pip
After installing, you can use it to install other Python packages. For example, installing the
requests
package, type the following command:pip install requests
Conclusion
Using Python in Termux is a convenient way to develop and run Python scripts directly on your Android device. By following the steps outlined in this guide, you can install Python, create and run Python scripts, and install additional Python packages using pip
.