Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No module named matplotlib.colors #18

Open
HundredVisionsGuy opened this issue Apr 25, 2020 · 5 comments
Open

No module named matplotlib.colors #18

HundredVisionsGuy opened this issue Apr 25, 2020 · 5 comments

Comments

@HundredVisionsGuy
Copy link

ImageDemos.py keeps crashing with the no module named matplotlib.colors.

I imported matplotlib, and it was successful, but I still get the following error when trying to run ImageDemos.py:

Starting, please wait...
PathSetter.py: Parent folder added to sys.path
Traceback (most recent call last):
  File "ImageDemos.py", line 26, in <module>
    from LEDAnimator import ImageAnimations
  File "/home/pi/Documents/python_projects/led_animator/LEDAnimator/ImageAnimations.py", line 13, in <module>
    from ImageAnimBase import ImageAnimBase
  File "/home/pi/Documents/python_projects/led_animator/LEDAnimator/ImageAnimBase.py", line 10, in <module>
    from AnimBase import AnimBase
  File "/home/pi/Documents/python_projects/led_animator/LEDAnimator/AnimBase.py", line 13, in <module>
    from matplotlib.colors import *
ImportError: No module named matplotlib.colors

Any thoughts?

PS - I forked your project, which is why the path looks different. I'm also running this on a Pi 4.

@BNNorman
Copy link
Owner

Firstly, thanks for looking at this code - I haven't played with it for a very long time (2 years according to my last fix).

It sounds, to me, like you haven't got the python matplotlib library on your Pi. It can be installed like this:-

pip install matplotlib

Of course, there may be more than one version of Python on your machine. The pip command above would normally default to Python2.x. You could try

pip3 install matplotlib

Things can get complicated installing Python packages. I'm no expert but bear this in mind...

You might need to add sudo to the start of the pip command to be able to update the system wide python packages.

If you are running python in a virtual environment you should be inside the virtual env then run pip.

Again, I'm no expert there I tend to use PyCharm and installing packages into a vritual environment is easy. However PyCharm on my Pi4 is mostly sloooow when typing stuff quickly.

Hope that helps
Regards
Brian

@HundredVisionsGuy
Copy link
Author

Thanks for the quick response.

I tried the following commands to install (and then reinstall matplotlib). Most of the time, it said it was successful with an 'requirement already satisfied' response.
sudo apt-get build-dep python-matplotlib
pip install matplotlib
pip3 install matplotlib
pip install python-matplotlib

What I didn't try was the virtual env. I have very little experience with a virtual environment, to the point where I'll need to do a little research on how to do that.

I'll let you know once I've tried your suggestions with a virtual environment. I probably won't get to it until the weekend, so I'm in no rush. Plus it's all just me having fun experimenting with various libraries.

On a side note, I noticed on ImageDemos.py there are two lines with the Python2 print command (as opposed to a print function print()), so I assumed this was all written in Python 2.

@BNNorman
Copy link
Owner

The 'requirement satisfied' relates to dependencies that don't need to be installed because they are up to date. I'm sure you know that.

Before attempting to install matplot lib did you apt update/upgrade the Pi?

Did you try 'sudo pip install'?

This might help: https://raspberrypi.stackexchange.com/questions/15420/how-to-install-python3-matplotlib-on-raspi/15457

You would know if you were working in a virtual environment because you would have to create one and switch into it. The advantage of those is that you don't clutter projects with un-necessary limports. You can zip/tar them up and copy them elsewhere.

Did you check that matplot lib was installed? Start python and try to import it?

Yes, originally written with python 2 on my machine but 'print' should be the only thing that was Python 2 specific (IIRC) so just add brackets. If I get time I might add a test for python version or import futures but I'm a bit busy with a micropython project at the moment

@inextricable-code
Copy link

I'm also having this same issue and can't seem to fix it. Did you manage to get it fixed @HundredVisionsGuy ?

@BNNorman
Copy link
Owner

This is a problem caused by a failed matplotlib install or a dependency (like numpy)

On my PC (Python 3.8) this works

import matplotlib.colors

and checking it with ...

>>> dir(matplotlib.colors)
['BASE_COLORS', 'BoundaryNorm', 'CSS4_COLORS', 'ColorConverter', 'Colormap', 'DivergingNorm', 'LightSource', 'LinearSegmentedColormap', 'ListedColormap', 'LogNorm', 'NoNorm', 'Normalize', 'PowerNorm', 'Sized', 'SymLogNorm', 'TABLEAU_COLORS', 'TwoSlopeNorm', 'XKCD_COLORS', '_ColorMapping', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_colors_full_map', '_create_lookup_table', '_is_nth_color', '_sanitize_extrema', '_to_rgba_no_colorcycle', '_vector_magnitude', 'cbook', 'cnames', 'colorConverter', 'docstring', 'from_levels_and_colors', 'functools', 'get_named_colors_mapping', 'hex2color', 'hexColorPattern', 'hsv_to_rgb', 'is_color_like', 'itertools', 'makeMappingArray', 'np', 're', 'rgb2hex', 'rgb_to_hsv', 'same_color', 'to_hex', 'to_rgb', 'to_rgba', 'to_rgba_array']
>>>

On my Pi 3 with python3.5 I get the followng with matplotlib 3.0.3 and numpy 18.5

>>> import matplotlib.colors
>>> dir(matplotlib.colors)
['BASE_COLORS', 'BoundaryNorm', 'CSS4_COLORS', 'ColorConverter', 'Colormap', 'LightSource', 'LinearSegmentedColormap', 'ListedColormap', 'LogNorm', 'NoNorm', 'Normalize', 'PowerNorm', 'Sized', 'SymLogNorm', 'TABLEAU_COLORS', 'XKCD_COLORS', '_ColorMapping', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_colors_full_map', '_is_nth_color', '_sanitize_extrema', '_to_rgba_no_colorcycle', '_vector_magnitude', 'cbook', 'cnames', 'colorConverter', 'from_levels_and_colors', 'get_named_colors_mapping', 'hex2color', 'hexColorPattern', 'hsv_to_rgb', 'is_color_like', 'itertools', 'makeMappingArray', 'np', 're', 'rgb2hex', 'rgb_to_hsv', 'same_color', 'to_hex', 'to_rgb', 'to_rgba', 'to_rgba_array']
>>>

You probably just need to make sure you only have one version of numpy and matplotlib (pref latest). For python3.5 you can look in these folders:-

 /home/pi/.local/lib/python3.5/site-packages
/usr/local/lib/python3.5/dist-packages

You can remove a package by simply removing the folders.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants