sonettguy
Posts: 142
Joined: Wed Jan 10, 2018 7:29 pm
Location: texas, USA

matplotlib install: My wheels ran over my pip

Sun Apr 07, 2019 9:32 pm

Newbie, here. I'm struggling to do what I would think a simple task; install matplotlib.

I went to https://matplotlib.org/users/installing.html to install the program on a pi zero w running raspbian stretch, updated, upgraded. I started with "Installing Official Release." Sounds good, right? As I executed the first instruction,

Code: Select all

python -m pip install -U pip
I saw that the Third Party Distribution section had an install specific to Debian. Score! So, I went on to

Code: Select all

sudo apt-get install python3-matplotlib
OK, done! I thought. I looked through both installs and saw no errors. Nice! I also did installed subprocess32 without errors since I'm trying to use a program in Python 2.7.

So, I ran my hastily coded trial program I called 'temp.'

Code: Select all

user@host:~/esi $ sudo python temp
Traceback (most recent call last):
File "temp", line 4, in <module>
import matplotlib as mpl
ImportError: No module named matplotlib

user@host:~/esi $ cat temp
#/usr/bin/python
#
import os
import matplotlib as mpl
mpl.use("Agg")
import numpy as np
import matplotlib.pyplot as plt
plt.rcParams['text.usetex']=True

data=np.random.rand(50,50)
plt.imshow(data, interpolation='nearest')
plt.xlabel('X Label')
plt.savefig('agg.eps')
os.system('epspdf agg.eps agg.pdf')
x=[5,2,9,4,7]
y=[10,5,8,4,2]
plt.plot(x,y)
plt.show()
Hm. No module named matplotlib. I went to the forums and tried about a hundred fixes, got lost with my head in my backend (cairo v agg, etc) and trying to reinstall using my wheel

Code: Select all

python -m pip install -U matplotlib
and I think my wheel ran over my pip.

Code: Select all

sudo apt install libffi-dev libffi6
sudo pip3 install cffi
sudo pip3 install cairocffi
Thinking bad things happened because the wheel install just have a long list of errors and no line of execution.

Now, I'm so confused over python and python3, over matplotlib and matplotlib.pyplot, and wheels and pips that I can't even understand what I'm reading anymore. Here is a little more information that might or might not be helpful.

Code: Select all

usr@host:~/esi $ sudo python temp
Traceback (most recent call last):
File "temp", line 4, in <module>
import matplotlib as mpl
ImportError: No module named matplotlib

usr@host:~/esi $ apt-cache policy python-matplotlib
python-matplotlib:
Installed: (none)
Candidate: 2.0.0+dfsg1-2
Version table:
2.0.0+dfsg1-2 500
500 http://mirrordirector.raspbian.org/raspbian stretch/main
armhf Packages 

usr@host:~/esi $ apt-cache policy python3-matplotlib
python3-matplotlib:
Installed: 2.0.0+dfsg1-2
Candidate: 2.0.0+dfsg1-2
Version table:
*** 2.0.0+dfsg1-2 500
500 http://mirrordirector.raspbian.org/raspbian stretch/main
armhf Packages 100 /var/lib/dpkg/status

usr@host:~/esi $ sudo find / -name matplotlib*
/home/pi/Documents/matplotlib_fail.odt
/home/pi/.cache/pip/wheels/55/b7/9b/bb44c9cc9b63cf0ee150537dbcd78717f499c4e2fd2dc6f7a9/matplotlib-2.2.4-cp27-cp27mu-linux_armv6l.whl
/home/pi/.cache/matplotlib
/root/.config/matplotlib
/root/.cache/matplotlib
/etc/matplotlibrc
/usr/share/matplotlib
/usr/share/matplotlib/mpl-data/images/matplotlib.ppm
/usr/share/matplotlib/mpl-data/images/matplotlib.png
/usr/share/matplotlib/mpl-data/images/matplotlib_large.png
/usr/share/matplotlib/mpl-data/images/matplotlib.pdf
/usr/share/matplotlib/mpl-data/images/matplotlib.svg
/usr/share/matplotlib/matplotlib.conf
/usr/share/matplotlib/matplotlib.conf/matplotlibrc.template
/usr/lib/python3/dist-packages/matplotlib
/usr/lib/python3/dist-packages/matplotlib-2.0.0-nspkg.pth
/usr/lib/python3/dist-packages/matplotlib-2.0.0.egg-info
find: ‘/run/user/1000/gvfs’: Permission denied
Bottom line, my first install had no errors, yet my python 2.7 program results in "what matplotlib, I don't see no matplotlib." Further re-install attempts using wheels failed. I most recently did an apt-get install --reinstall that worked again without error, then rebooted, but with the same result: "ImportError: No module named matplotlib." I think as a newbie, I'm missing something very basic about python and python3 and how they work with matplotlib. I'm wishing I had started with Anaconda.

I've seen many posts about matplotlib installation, but most say things like it works with python 2.7 but not python3. In my case, my pi can't even find it after a successful install.

If someone could perhaps get me back on the right track, I would certainly appreciate it.

Andyroo

Re: matplotlib install: My wheels ran over my pip

Mon Apr 08, 2019 11:00 pm

Three quick thoughts (and I do not know this for sure)

1) Sudo is not need to run the program. It’s needed for the apt part of the install but that’s it.
2) The dependencies listed on the link is for Python after 3.5 so you need to start it as

Code: Select all

python3 temp.py
where temp.py is your program. There are a lot of other Programs / modules that are also needed...
3) The example for fill plot shows:

Code: Select all

import matplotlib.pyplot as plt
as the import command - matplotlib is part of the pyplot module and not the module itself!

sonettguy
Posts: 142
Joined: Wed Jan 10, 2018 7:29 pm
Location: texas, USA

Re: matplotlib install: My wheels ran over my pip

Mon Apr 08, 2019 11:15 pm

Thanks, @Andyroo. And, thanks in particular for the last line. I thought it was the other way around; that pyplot was a part of matplotlib.

What is the difference between import matplotlib and import matplotlib.pyplot?

Andyroo

Re: matplotlib install: My wheels ran over my pip

Tue Apr 09, 2019 12:06 am

It all ties into the directory structure of the package...

Code: Select all

So in your case of 
import matplotlib
/matplotlib.py
would get you to the python program and let you import it

import matplotlib.pyplot
/pyplot
    /matplotlib.py
So the first case is a library or project containing just matplotlib where the second project could contain just more than matplotlib.

Before anyone chips in - I know this is crude and very basic but it’s as simple as I can make it as I cannot find a good example and I am finding my around this (I.e. I’m on page two trying to explain this to the OP who is on page one) :lol:

sonettguy
Posts: 142
Joined: Wed Jan 10, 2018 7:29 pm
Location: texas, USA

Re: matplotlib install: My wheels ran over my pip

Thu Apr 11, 2019 6:59 pm

Still need help installing matplotlib, please. Anyone?

Return to “Troubleshooting”