Error while import tensorflow module

I’ve installed TensorFlow, but when i try import tensorflow it comes out with error.

import tensorflow
2022-06-14 10:04:12.568302: I tensorflow/stream_executor/platform/default/] Successfully opened dynamic library
Traceback (most recent call last):
File “”, line 1, in
File “/usr/local/lib/python3.6/dist-packages/tensorflow/”, line 54, in
from ._api.v2 import compat
File “/usr/local/lib/python3.6/dist-packages/tensorflow/_api/v2/compat/”, line 39, in
from . import v1
File “/usr/local/lib/python3.6/dist-packages/tensorflow/_api/v2/compat/v1/”, line 34, in
from . import compat
File “/usr/local/lib/python3.6/dist-packages/tensorflow/_api/v2/compat/v1/compat/”, line 39, in
from . import v1
File “/usr/local/lib/python3.6/dist-packages/tensorflow/_api/v2/compat/v1/compat/v1/”, line 682, in
from tensorflow.python.keras.api._v1 import keras
File “/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/api/”, line 10, in
from . import keras
File “/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/api/keras/”, line 19, in
from . import datasets
File “/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/api/keras/datasets/”, line 14, in
from . import imdb
File “/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/api/keras/datasets/imdb/”, line 11, in
from import get_word_index
File “/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/datasets/”, line 25, in
from tensorflow.python.keras.preprocessing.sequence import _remove_long_seq
File “/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/preprocessing/”, line 26, in
from tensorflow.python.keras.preprocessing import image
File “/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/preprocessing/”, line 24, in
from keras_preprocessing import image
File “/usr/local/lib/python3.6/dist-packages/keras_preprocessing/image/”, line 5, in
from .affine_transformations import *
File “/usr/local/lib/python3.6/dist-packages/keras_preprocessing/image/”, line 9, in
from .utils import (array_to_img,
File “/usr/local/lib/python3.6/dist-packages/keras_preprocessing/image/”, line 23, in
‘nearest’: pil_image.NEAREST,
AttributeError: module ‘PIL.Image’ has no attribute ‘NEAREST’

tensorflow version 2.3.1+nv20.12
Thank You.


It looks like some compatibility issue with the pillow.

Which version do you install?
Would you mind upgrading the pillow to the latest and trying it again?


Pillow version 9.0.1


Would you mind trying the veresion 8.4.0 to see if it works?

Sorry for late reply , so i downgraded the version to 5.3.0 it work well

Thank you

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.