Python Forum
Matplotlib Doesn't Work - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Matplotlib Doesn't Work (/thread-2222.html)



Matplotlib Doesn't Work - Ian12290 - Feb-27-2017

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!


RE: Matplotlib Doesn't Work - wavic - Feb-27-2017

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


RE: Matplotlib Doesn't Work - Ian12290 - Feb-27-2017

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


RE: Matplotlib Doesn't Work - buran - Feb-27-2017

I'm almost certain that the problem with the matplotlib is because your file is also named matplotlib. Select different name for your file.


RE: Matplotlib Doesn't Work - wavic - Feb-27-2017

(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.


RE: Matplotlib Doesn't Work - Ian12290 - Feb-28-2017

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?


RE: Matplotlib Doesn't Work - buran - Feb-28-2017

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