'pip install matplotlib does not work under termux (Android)

I installed termux on my Android tablet, and was able to successfully install Python 3.9 and Numpy, but not matplotlib. Apparently the .whl was downloaded and cached, and now when I try to install, whether using pip or pkg it attempts to use the cached .whl file. I tried clearing memory and reinstalling everything from scratch, but it still downloads the same .whl, with the same result. (The termux wiki provided no clues that I could find) Anybody have a work around or fix?



Solution 1:[1]

As I did not want to install Ubuntu on the tablet, what I wound up doing was installing Pydroid 3. I was then able to install Numpy and Matplotlib using pip. Thanks for the effort!

Solution 2:[2]

I had the same issue, but the existing answers did not work for me. In my case, it turned out to be an issue with installing Pillow. If "pip install Pillow" does not work, you may have the same issue.

To fix it, follow the image editor installation instructions for Pillow given on the Termux wiki. Look at the Python section of this page: https://wiki.termux.com/wiki/Image_Editors. After that "pip install matplotlib" worked without issue.

Solution 3:[3]

As listed on the termux wiki.

pkg in build-essential -y 
git clone https://github.com/matplotlib/matplotlib
cd matplotlib
sed 's@#enable_lto = True@enable_lto = False@g' setup.cfg.template > setup.cfg
pip install .

Solution 4:[4]

Yes.

1- Install Ubuntu for termux from the link below (follow the steps) https://github.com/MFDGaming/ubuntu-in-termux

2- Install python3 and pip3 as you would do normally in Ubuntu (don't need to use 'sudo' as you are logged as the root).

3- Install matplotlib and the other packages, like jupyter etc using pip3.

Solution 5:[5]

Part of the answer that worked for me is given by Krishna Kanhaya and Garam Lee. However I had to make some changes to the sed command, which are also not listed in the termux wiki:

Be sure to install all dependencies as described in the wiki. Follow the answer by Krishna Kanhaya/the workaround from the wiki.

Replace the line from answer by Krishna Kanhaya or the wiki.

sed 's@#enable_lto = True@enable_lto = False@g' setup.cfg.template > setup.cfg with

sed 's/#enable_lto = True/enable_lto = False/g' mplsetup.cfg.template > mplsetup.cfg

It will create a copy of template setup file and changes the enable_lto = True to enable_lto = False and rename it to mplsetup.cfg.

You can access mplsetup.cfg.template in beforehand with e.g.

less mplsetup.cfg.template

to read the instructions there.

I don't know why I had to make these changes. Maybe they changed the name of the setup file for matplotlib with a newer version?

In the end check if the line enable_lto = False

appears once in in mplsetup.cfg with the less command. Try then the installation directly from within the directory with

pip install .

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 24b4Jeff
Solution 2 Anunnaki
Solution 3 psmears
Solution 4 Athkalan al-Himyari
Solution 5