ImportError: cannot import name 'colors'
7 Dec 2025
1 min read
ImportError: cannot import name ‘colors’
$ python -c "from matplotlib import colors"
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: cannot import name 'colors' from 'matplotlib'
Why this happens
colors is a submodule: matplotlib.colors.
Fix
Import the correct submodule.
Wrong code
from matplotlib import colors
colors.to_rgb('red')
Fixed code
import matplotlib.colors as colors
colors.to_rgb('red')