Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python

Jonathan Grieve
MOD
Jonathan Grieve
Treehouse Moderator 91,253 Points

Matplotlib outside of Jupyter

Does Matploib require using Jupyter to work?

I've been trying to run scripts built in Jupyter in the command line but pyplot doesn't seem to be recogised.

In fact, despite installing matplotlib with pip, sometimes that doesn't seem to be recognised either.

$ python old_faithful.py
Traceback (most recent call last):
  File "old_faithful.py", line 2, in <module>
    import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'

Is this possible or should I stick with Jupyter.

1 Answer

No, you can use Matplotlib pretty much anywhere, not just in Jupyter.

I'm using Ubuntu and I successfully installed Matplotlib using the command pip3 install matplotlib. Did you use pip instead of pip3?

Also make sure that you are using Python 3 on your local computer (or elsewhere). In the command line, type python3 instead of python.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

This is interesting because I have Python3 setup on both my systems (Windows 10) and they show up as the latest version of Python 3.

I ended up trying both pip and pip3 and even though the terminal reports installations when I run the script it comes up ModuleNotFound, so there's some funny stuff going on, I reckon.

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,253 Points

Thanks Alexander,

I've just managed to generate a figure on my laptop which confirms that it works. I already had the packages I needed so I was able to call the file with simply the python command. It does mean there's something wrong with my installation on the PC though that's preventing the images from being created.

Will investiate :)