[Tutor] Finding Matplotlib somewhere ADDING ADDITIONAL INFORMATION

Mats Wichmann mats at wichmann.us
Sun Nov 8 18:32:07 EST 2020


On 11/8/20 3:31 PM, Ken Green wrote:
> ADDITION INFORMATION:
> 
> I forgot to make mention that I have both Python 2 and 3 in separate 
> folders and I am using Linux Ubuntu 20.04.1.
> 
> 
> When running the following portion of a bioyear.py program (dated some 8 
> years ago from Python 2 and now trying to run it in Python 3.
> 
> Matplotlib was installed by pip and apt-get and verified by pip3 list. 
> When typing each of the following lines in python 3 shell command line, 
> no error were noted.
> 
> from datetime import date
> import matplotlib.dates
> from pylab import *
> from numpy import array,sin,pi
> from sys import argv
> 
> Traceback (most recent call last):
>    File "bioyear.py", line 24, in <module>
>      import matplotlib.dates
> ImportError: No module named matplotlib.dates
> 
> It seems not to find matplotlib anywhere but it was verified by sudo 
> apt-get and pip. How can I incorporate it into the program?

Rule 1: if an import fails, it's always a path problem.
There is no Rule 2.

Sorry, being cute doesn't actually help solve your problem.

In general, for the Python version you expect to use, use the same 
Python to install packages, that is, if pythonFOO works for you, and 
you're going to use it to run something, then install with

pythonFOO -m pip install PKG

or, or that's a _system_ version of Python, you probably want to install 
extra packages with the -U/--user option.

If you're going to use the system Python, and there are packages 
available, it should be okay to use the matching package. Maybe.

Do you know that pip3 refers to the Python you want to use?

Your information leaves some questions unanswered: the interactive 
commands are fine. Did you get the same Python REPL as the Python you're 
using to run the failing program?

 > Matplotlib was installed by pip and apt-get and verified by pip3 list

If you're running Ubuntu 20.04, and haven't installed the 
python-is-python3 package, then by default "python" will be 2.7.  and 
pip3 is for python3.  See the possibilities for confusion when using an 
old piece of software?


More information about the Tutor mailing list