Pyhton
Last updated
Last updated
To run your python file click your python file you want to run and when your file was loaded click the Run button.'
Python is an interpreted, high-level, general-purpose programming language. Created by Guido van Rossum and first released in 1991, Python's design philosophy emphasizes code readability with its notable use of significant whitespace. Its language constructs and object-oriented approach aim to help programmers write clear, logical code for small and large-scale projects.
In Termux Python v3.x can be installed by executing
Legacy, deprecated version 2.7.x can be installed by
Warning: upgrading major/minor version of Python package, for example from Python 3.8 to 3.9, will make all your currently installed modules unusable. You will need to reinstall them. However upgrading patch versions, for example from 3.8.1 to 3.8.2, is safe.
Due to our infrastructure limits, we do not provide older versions of packages. If you accidentally upgraded to unsuitable Python version and do not have backups to rollback, do not complain! We recommend doing backups of $PREFIX for developers and other people who rely on specific software versions.
After installing Python, pip
(pip2
if using python2) package manager will be available. Here is a quick tutorial about its usage.
Installing a new Python module:
Uninstalling Python module:
Listing installed modules:
When installing Python modules, it is highly recommended to have a package build-essential
to be installed - some modules compile native extensions during their installation.
It is assumed that you have build-essential
or at least clang
, make
and pkg-config
installed.
It also assumed that termux-exec
is not broken and works on your device. Environment variable LD_PRELOAD
is not tampered or unset. Otherwise you will need to patch modules' source code to fix all shebangs!
Tip: help us to collect more information about installing Python modules in Termux. You can also help to keep this information up-to-date, because current instructions may eventually become obsolete.
Package | Description | Dependencies | Special Instructions | |
---|---|---|---|---|
electrum | Lightweight Bitcoin wallet. https://electrum.org/ |
| ||
gmpy2 | C-coded Python modules for fast multiple-precision arithmetic. https://github.com/aleaxit/gmpy | libgmp libmpc libmpfr | ||
lxml | Bindings to libxml2 and libxslt. https://lxml.de/ | libxml2 libxslt | ||
Numpy | The fundamental package for scientific computing with Python |
| ||
matplotlib | A plotting library for Python. https://matplotlib.org/ | freetype libjpeg-turbo libpng | On some devices a patch/config file is needed to get rid of the
| |
pandas | Flexible and powerful data analysis / manipulation library for Python. https://pandas.pydata.org/ |
| ||
pynacl | Bindings to the Networking and Cryptography library. https://pypi.python.org/pypi/PyNaCl | libsodium | ||
pillow | Python Imaging Library. https://pillow.readthedocs.io/en/stable/ | libjpeg-turbo libpng | 64-bit devices require running | |
pyzmq | Bindings to libzmq. https://pyzmq.readthedocs.io/en/latest/ | libzmq | On some devices the libzmq library can't be found by setup.py. If |
Some Python modules may not be easy to install. Here are collected information on how to get them available in your Termux.
Numpy and Scipy
Building complex software like numpy and scipy is tedious. Therefore, Termux user its-pointless (aka live_the_dream) has packaged this software and maintain a Termux APT repository with these and many other useful packages.
Before Numpy/Scipy installation, you need to subscribe to APT repository:
Then you can install Numpy or Scipy like a regular Termux package:
OpenCV
Instructions taken from #512 and #1992. OpenCV is not a Python package but it includes the Python bindings (known as opencv-python in pip).
OpenCV needs to be built from source using CMake, install it and other dependencies with:
Numpy is also required, see instructions for installing it above.
There might be other required dependecies as well, see the OpenCV docs for the list.
The rest of the instructions can be copy-pasted straight away, but if you are not sure if you have all dependencies then it might be best to do it in two steps: first all commands up until the LDFLAGS=" -llog" cmake
command and then in a second step make and make install.
To get the sources, git clone (from a suitable folder):
You should now be in the opencv folder. Let's create a build folder where we will build the package:
To configure the package for python3 but not python2 (change the on/off flags to use python2 instead of python3) we run:
Last command will throw errors if there are missing dependencies. After this we can compile the package with
and then install the files with
Tkinter
Tkinter is splitted of from the python
package and can be installed by
We do not provide Tkinter for Python v2.7.x.
Since Tkinter is a graphical library, it will work only if X Windows System environment is installed and running. How to do this, see page Graphical Environment.
Some modules may not be installable without patching. They should be installed from source code. Here is a quick how-to about installing Python modules from source code.
1. Obtain the source code. You can clone a git repository of your package:
or download source bundle with pip
:
2. Optionally, apply the desired changes to source code. There no universal guides on that, perform this step on your own.
3. Optionally, fix the all shebangs. This is not needed if termux-exec
is installed and works correctly.
4. Finally install the package: