Python Forum
Spent over an hour trying to get matplotlib to work
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Spent over an hour trying to get matplotlib to work
#1
Is anyone able to help? I have Python 3.8 installed on my Windows 10 system (and the installation did apparently show as working).

But when I attempt this (from the excellent Python Crash Course):
[Image: 1.jpg]

I just get this:
[Image: 2.jpg]

I have googled and tried YouTube for over an hour and still can't get this working. Any advice hugely appreciated!
Reply
#2
Have you actually installed the library? Most libraries (the ones not in the standard library) need to be downloaded and installed separately.

If you haven't already done it,use the "pip install matplotlib" command from the command prompt in the same directory as your python exe.

If this is your first time doing this and you're having trouble, read this setup guide.
Reply
#3
It would help to know what you tried and what the problems were.
Reply
#4
Thanks, both. As I said, the problem each time is the above error message.

Knight18, I think it installed just fine. It certainly had the bars for installation go up to 100% etc. The only thing I would say is different is I typed Windows key CMD to open the command prompt to install. I don't think I did as you suggest and opened it from the same directory as the exe.
Reply
#5
(Aug-31-2020, 09:56 AM)Tomalak Wrote: The only thing I would say is different is I typed Windows key CMD to open the command prompt to install. I don't think I did as you suggest and opened it from the same directory as the exe.
Look this run see that pip -V is showing which version it install to.
Then to test that Matplotlib also work from cmd.
Microsoft Windows [Version 10.0.18362.1016]
(c) 2019 Microsoft Corporation. Med enerett.

C:\Users\Tom>cd\

# Test pip
C:\>pip -V
pip 20.2.2 from c:\python38\lib\site-packages\pip (python 3.8)

# Test python
C:\>python -V
Python 3.8.3

# Install
C:\>pip install matplotlib
Requirement already satisfied: matplotlib in c:\python38\lib\site-packages (3.2.
2)

# Test that it work.
C:\>python
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>>
>>> matplotlib.__version__
'3.2.2'
>>> exit()

C:\> 
Now that all work here make sure you choose this Python version is use a editor.
It's often called configure a python interpreter in editors.
Quote:I don't think I did as you suggest and opened it from the same directory as the exe
You don't need that,just make sure python and pip command work from anywhere in cmd.
Look at this Python 3.8 (3.6-3.7) and pip installation under Windows
Reply
#6
Thanks, snipsat. I'll try that as soon as I'm home.
Reply
#7
(Aug-31-2020, 10:13 AM)snippsat Wrote:
(Aug-31-2020, 09:56 AM)Tomalak Wrote: The only thing I would say is different is I typed Windows key CMD to open the command prompt to install. I don't think I did as you suggest and opened it from the same directory as the exe.
Look this run see that pip -V is showing which version it install to.
Then to test that Matplotlib also work from cmd.
Microsoft Windows [Version 10.0.18362.1016]
(c) 2019 Microsoft Corporation. Med enerett.

C:\Users\Tom>cd\

# Test pip
C:\>pip -V
pip 20.2.2 from c:\python38\lib\site-packages\pip (python 3.8)

# Test python
C:\>python -V
Python 3.8.3

# Install
C:\>pip install matplotlib
Requirement already satisfied: matplotlib in c:\python38\lib\site-packages (3.2.
2)

# Test that it work.
C:\>python
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AM
D64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>>
>>> matplotlib.__version__
'3.2.2'
>>> exit()

C:\> 
Now that all work here make sure you choose this Python version is use a editor.
It's often called configure a python interpreter in editors.
Quote:I don't think I did as you suggest and opened it from the same directory as the exe
You don't need that,just make sure python and pip command work from anywhere in cmd.
Look at this Python 3.8 (3.6-3.7) and pip installation under Windows

Ok, this is all obvs very helpful. Here is what happened when I typed each line in cmd.

Quote:pip -V
pip 20.2.2 from c:\users\peter\appdata\local\programs\python\python38-32\lib\site-packages\pip (python 3.8)

Quote:pip install matplotlib
Requirement already satisfied: matplotlib in c:\users\peter\appdata\local\programs\python\python38-32\lib\site-packages (3.3.1)
Requirement already satisfied: cycler>=0.10 in c:\users\peter\appdata\local\programs\python\python38-32\lib\site-packages (from matplotlib) (0.10.0)
Requirement already satisfied: python-dateutil>=2.1 in c:\users\peter\appdata\local\programs\python\python38-32\lib\site-packages (from matplotlib) (2.8.1)
Requirement already satisfied: numpy>=1.15 in c:\users\peter\appdata\local\programs\python\python38-32\lib\site-packages (from matplotlib) (1.19.1)
Requirement already satisfied: kiwisolver>=1.0.1 in c:\users\peter\appdata\local\programs\python\python38-32\lib\site-packages (from matplotlib) (1.2.0)
Requirement already satisfied: pillow>=6.2.0 in c:\users\peter\appdata\local\programs\python\python38-32\lib\site-packages (from matplotlib) (7.2.0)
Requirement already satisfied: pyparsing!=2.0.4,!=2.1.2,!=2.1.6,>=2.0.3 in c:\users\peter\appdata\local\programs\python\python38-32\lib\site-packages (from matplotlib) (2.4.7)
Requirement already satisfied: certifi>=2020.06.20 in c:\users\peter\appdata\local\programs\python\python38-32\lib\site-packages (from matplotlib) (2020.6.20)
Requirement already satisfied: six in c:\users\peter\appdata\local\programs\python\python38-32\lib\site-packages (from cycler>=0.10->matplotlib) (1.15.0)

Quote:python
Python 3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.

Quote:>>> import matplotlib
>>>
>>> matplotlib._version_
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'matplotlib' has no attribute '_version_'

So it seems like every line you wanted me to type worked fine apart from the last one?

This is what I get when I try to do a basic thing in matplotlib:
[Image: 3.jpg]
Reply
#8
(Aug-31-2020, 06:56 PM)Tomalak Wrote: So it seems like every line you wanted me to type worked fine apart from the last one?
It's not one _ but two __version__
So it work as you don't get error on import.

Quote:This is what I get when I try to do a basic thing in matplotlib:
As i mention so most you configure editors in this case Sublime to use Python 3.8.
Add this in code then you see what version you run,and Path it use.
import sys

print(sys.version)
print(sys.executable)
VS Code is an other option that's a very good editor for Python and free.
VS Code from start
Reply
#9
Thanks for the correction! Ok, so here is what I get:

Quote:>>> matplotlib.__version__
'3.3.1'
>>> import sys
>>>
>>> print(sys.version)
3.8.5 (tags/v3.8.5:580fbb0, Jul 20 2020, 15:43:08) [MSC v.1926 32 bit (Intel)]
>>> print(sys.executable)
C:\Users\Peter\AppData\Local\Programs\Python\Python38-32\python.exe


Quote:Add this in code then you see what version you run,and Path it use...

Add it where?
Reply
#10
Now is all okay from command lime,so now need to setup editor to you Python 3.8,look at link i posted.
I meant you add that last code in Sublime and run,then you see what version you run in Sublime.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Matplotlib Doesn't Work Ian12290 6 13,253 Feb-28-2017, 06:18 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020