Data Analysis with Python Projects - Page View Time Series Visualizer

Tell us what’s happening:

AttributeError: module ‘numpy.typing’ has no attribute ‘NDArray’

After I downgrade my NumPy to 1.20, this error arise.

Your code so far

gitpod /workspace/boilerplate-page-view-time-series-visualizer (main) $ /home/gitpod/.pyenv/versions/3.8.20/bin/python /workspace/boilerplate-page-view-time-series-visualizer/main.py
Traceback (most recent call last):
File “/workspace/boilerplate-page-view-time-series-visualizer/main.py”, line 2, in
import time_series_visualizer
File “/workspace/boilerplate-page-view-time-series-visualizer/time_series_visualizer.py”, line 1, in
import matplotlib.pyplot as plt
File “/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/matplotlib/init.py”, line 129, in
from . import _api, _version, cbook, _docstring, rcsetup
File “/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/matplotlib/rcsetup.py”, line 27, in
from matplotlib.colors import Colormap, is_color_like
File “/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/matplotlib/colors.py”, line 51, in
from PIL import Image
File “/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/PIL/Image.py”, line 68, in
from ._typing import StrOrBytesPath, TypeGuard
File “/workspace/.pyenv_mirror/user/current/lib/python3.8/site-packages/PIL/_typing.py”, line 10, in
NumpyArray = npt.NDArray[Any]
AttributeError: module ‘numpy.typing’ has no attribute ‘NDArray’

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36 Edg/137.0.0.0

Challenge Information:

Data Analysis with Python Projects - Page View Time Series Visualizer

1 Like

Why did you downgrade NumPy?

I reviewed your error, and it appears that the specific AttributeError is due to the fact that the NDArray type was introduced in NumPy version 1.21. Since you’re using an earlier version (1.20), that attribute doesn’t exist, which leads to the import error in Pillow.
No need to downgrade. Instead, consider why the error only occurs after changing versions. Reviewing the official version documentation can help clarify what’s supported and what’s not.

Let us know if this helps. Good luck!