Python Forum
Matplotlib Doesn't Work
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Matplotlib Doesn't Work
#1
Hi everyone!

I successfully downloaded both Pygame and Matplotlib on my Mac (OSX), but neither seem to work when I import them.

Matplotlib was successfully installed using Pip3, but I get this message when trying to use it: 
Error:
Traceback (most recent call last):   File "/Users/ianscalzo/Desktop/python_work/matplotlib.py", line 1, in <module>     import matplotlib.pyplot as plt   File "/Users/ianscalzo/Desktop/python_work/matplotlib.py", line 1, in <module>     import matplotlib.pyplot as plt ImportError: No module named 'matplotlib.pyplot'; 'matplotlib' is not a package
I also successfully installed Pygame using Homebrew, but that doesn't work either. I get this message while trying to run it:
Error:
Traceback (most recent call last):   File "/Users/ianscalzo/Desktop/alien_invsion/game_test.py", line 3, in <module>     import pygame ImportError: No module named 'pygame'
Please help me out!
Reply
#2
Add path to the modules in PYTHONPATH environment

If they are installed with pip, this can help you to see where they are located:

pip show pygame
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
This is what I got for Pyame:

Name: pygame
Version: 1.9.4.dev0
Summary: Python Game Development
Home-page: http://www.pygame.org
Author: Pete Shinners, Rene Dudfield, Marcus von Appen, Bob Pendleton, others...
Author-email: [email protected]
License: LGPL
Location: /usr/local/lib/python3.6/site-packages
Requires: 

And this is what I got for MatPlotLib:

Name: matplotlib
Version: 2.0.0
Summary: Python plotting package
Home-page: http://matplotlib.org
Author: John D. Hunter, Michael Droettboom
Author-email: matplotlib-users@python.org
License: BSD
Location: /Users/ianscalzo/Library/Python/3.6/lib/python/site-packages
Requires: python-dateutil, pyparsing, cycler, six, numpy, pytz
Reply
#4
I'm almost certain that the problem with the matplotlib is because your file is also named matplotlib. Select different name for your file.
Reply
#5
(Feb-27-2017, 07:15 PM)buran Wrote: I'm almost certain that the problem with the matplotlib is because your file is also named matplotlib. Select different name for your file.

Wow, I always forgot for this "option". It is named that way. As I see it in the error mesage.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#6
I renamed the file, but still get the same error message:

Traceback (most recent call last):
  File "/Users/ianscalzo/Desktop/python_work/plotting_test.py", line 1, in <module>
    import matplotlib as plt
  File "/Users/ianscalzo/Desktop/python_work/matplotlib.py", line 4, in <module>
    plt.plot(squares)
AttributeError: module 'matplotlib' has no attribute 'plot

Also, the filename issue couldn't be the reason I'm getting the error in Pygame as well. Could the Pygame error be due to the fact that it's a 32-Bit Pygame and not 64-Bit?
Reply
#7
Well, according to your traceback you have another matplotlib.py in your python-work folder and it imports that file. Note that it's different error this time...
For more info check the docs for The Module Search Path
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Convolution "same" in Python doesn't work as Matlab claw91 4 3,686 Oct-01-2020, 08:59 AM
Last Post: claw91
  Spent over an hour trying to get matplotlib to work Tomalak 10 4,270 Aug-31-2020, 10:48 PM
Last Post: Tomalak
  Numpy doesn't work in Spyder 4.1.3 player1681 1 2,103 Jun-02-2020, 11:26 AM
Last Post: jefsummers
  scipy interp2d doesn't work player1681 4 4,401 Feb-05-2020, 09:50 AM
Last Post: player1681
  cx_Freeze doesn't seem to work owenwalker65 7 16,747 Dec-07-2017, 02:23 AM
Last Post: issac_n

Forum Jump:

User Panel Messages

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